HDU4772-Zhuge Liang's Password

Zhuge Liang's Password
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 541    Accepted Submission(s): 370

Problem Description
  In the ancient three kingdom period, Zhuge Liang was the most famous and smart military leader. His enemy was Sima Yi, the military leader of Kingdom Wei. Sima Yi always looked stupid when fighting against Zhuge Liang. But it was Sima Yi who laughed to the
end.
  Zhuge Liang had led his army across the mountain Qi to attack Kingdom Wei for six times, which all failed. Because of the long journey, the food supply was a big problem. Zhuge Liang invented a kind of bull-like or horse-like robot called "Wooden Bull & Floating
Horse"(in abbreviation, WBFH) to carry food for the army. Every WBFH had a password lock. A WBFH would move if and only if the soldier entered the password. Zhuge Liang was always worrying about everything and always did trivial things by himself. Since Ma
Su lost Jieting and was killed by him, he didn't trust anyone's IQ any more. He thought the soldiers might forget the password of WBFHs. So he made two password cards for each WBFH. If the soldier operating a WBFH forgot the password or got killed, the password
still could be regained by those two password cards.
  Once, Sima Yi defeated Zhuge Liang again, and got many WBFHs in the battle field. But he didn't know the passwords. Ma Su's son betrayed Zhuge Liang and came to Sima Yi. He told Sima Yi the way to figure out the password by two cards.He said to Sima Yi:
  "A password card is a square grid consisting of N×N cells.In each cell,there is a number. Two password cards are of the same size. If you overlap them, you get two numbers in each cell. Those two numbers in a cell may be the same or not the same. You can
turn a card by 0 degree, 90 degrees, 180 degrees, or 270 degrees, and then overlap it on another. But flipping is not allowed. The maximum amount of cells which contains two equal numbers after overlapping, is the password. Please note that the two cards must
be totally overlapped. You can't only overlap a part of them."
  Now you should find a way to figure out the password for each WBFH as quickly as possible.
 

Input
  There are several test cases.
  In each test case:
  The first line contains a integer N, meaning that the password card is a N×N grid(0<N<=30).
  Then a N×N matrix follows ,describing a password card. Each element is an integer in a cell.
  Then another N×N matrix follows, describing another password card.
  Those integers are all no less than 0 and less than 300.
  The input ends with N = 0
 

Output
  For each test case, print the password.

 

Sample Input
2
1 2
3 4
5 6
7 8
2
10 20
30 13
90 10
13 21
0
 

Sample Output
0
2
 

Source
2013 Asia Hangzhou Regional Contest
 

//矩阵旋转
AC代码:

#include<stdio.h>
#include<string.h>
int a[40][40],b[40][40];
void Rotate(int n)
{
 int i,j,c[40][40],x=0,y=n-1;
    for(i=0;i<n;i++)
  for(j=0;j<n;j++)
  {
            c[i][j]=b[x++][y];
   if(x>n-1)
   {
                x=0;y--;
   }
  }

 for(i=0;i<n;i++)
  for(j=0;j<n;j++)
  {
   b[i][j]=c[i][j];
  }
}
int main()
{
 int i,j,n,m,sum,max;
 while(scanf("%d",&n),n!=0)
 {
  memset(a,0,sizeof(a));
  memset(b,0,sizeof(b));
  max=0;
  for(i=0;i<n;i++)
  for(j=0;j<n;j++)
   scanf("%d",&a[i][j]);
        for(i=0;i<n;i++)
  for(j=0;j<n;j++)
   scanf("%d",&b[i][j]);

  sum=0;
  for(i=0;i<n;i++)
  for(j=0;j<n;j++)
  {
   if(a[i][j]==b[i][j])
    sum++;
  }
  if(sum>max)
   max=sum;

  int T=3;
  while(T--)
  {
            Rotate(n);
   sum=0;
            for(i=0;i<n;i++)
   for(j=0;j<n;j++)
   {
    if(a[i][j]==b[i][j])
     sum++;
   }
   if(sum>max)
    max=sum;
  }
  printf("%d\n",max);
 }
 return 0;
}
时间: 2024-09-20 00:01:01

HDU4772-Zhuge Liang&#39;s Password的相关文章

hdu 4772 Zhuge Liang&#039;s Password

点击打开链接 题意:给定两个n*n的矩阵,矩阵可以进行90,180,270的旋转,问两个矩阵完全重合的时候最多有几个数是相同的 思路:暴力枚举第一个矩阵的4种情况和第二个矩阵匹配,求出ans 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int MAXN = 310; int n; int mat

ERROR 1045 (28000): Access denied for user &amp;#39;root&amp;#39;@&amp;#39;localhost&amp;#39; (using password: YES)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) root@mysql ~]# mysql -p -u root Enter password:  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) ERROR 1045 (28000): Access denied

mysql全局权限账户%登录不上ERROR 1045 (28000): Access denied for user &amp;#39;mhz&amp;#39;@&amp;#39;localhost&amp;#39; (using password: YES)

mysql全局权限账户%登录不上 ERROR 1045 (28000): Access denied for user 'mhz'@'localhost' (using password: YES)  解决 查看错误提示  有主机名字的就必须赋值主机名 mysql> GRANT ALL PRIVILEGES ON *.* TO 'mhz'@'mgr2' IDENTIFIED BY 'mhz' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 s

grid@m3&amp;#39;s password: Permission denied, please try again.

grid@m3's password: Permission denied, please try again. [grid@m1 .ssh]$ ssh-copy-id -i id_rsa.pub m3 10 grid@m3's password:  Permission denied, please try again. 出现这个问题  大多数是 passwd 的时候 密码没有输入正确  测试: 输入错误的密码: ogout [root@m2 ~]# su - grid [grid@m2 ~]

mysql报错 Access denied for user &amp;#39;root&amp;#39;@&amp;#39;localhost&amp;#39; (using password: YES)

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)at com.mysql.jdbc.MysqlIO.checkErrorPa

failed: Access denied for user &amp;#39;root&amp;#39;@&amp;#39;localhost&amp;#39; (using password: YES) at /usr/bin/innobackupex lin

[root@t1 /]#  innobackupex --user=root --password /mydata/data /tmp/dir/ InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved. This software is published under

Access denied for user: &amp;#39;root@localhost&amp;#39; (Using password: YES)

centos 安装mysql成功后 首次使用root登录发生:Access denied for user: 'root@localhost' (Using password: YES)   原因是mysql初始db中的mysql库user表中root密码为空 因此你需要修改root密码 首先执行:mysql -u root  进入mysql 库命令行 然后进入mysql库:use mysql; 进入后再执行修改密码即可:update user set password=password('aa

mariadb 1045 (28000): Access denied for user &amp;#39;root&amp;#39;@&amp;#39;localhost&amp;#39; (using password: YES)

[root@localhost /]# systemctl stop mariadb.service[root@localhost /]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & [1] 46043[root@localhost /]# 150131 03:15:27 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.150131 03:15:27

mysql修改密码后报错:ERROR 1045:Access denied for user:&amp;#39;root@localhost&amp;#39;(using password:YES)

  重装了mysql,修改了密码,却发现无法连接,报错:Access denied for user 'root'@'localhost' (using password:YES)       查找资料后,大概是说没有给root设置权限,修复方法如下:      1.停止mysql服务,最简单办法:打开任务管理器--服务,关闭MySql.      2.建立一个txt文件mysql-init.txt,本次放在C:\下.      3.txt文件输入:SET PASSWORD FOR 'root'