HDU 4772 Zhuge Liang's Password (简单模拟题)
来源:互联网 发布:天猫打印发货单软件 编辑:程序博客网 时间:2024/05/21 06:12
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772
题面:
Zhuge Liang's Password
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1404 Accepted Submission(s): 926
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.
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
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
21 23 45 67 8210 2030 1390 1013 210
Sample Output
02
Source
2013 Asia Hangzhou Regional Contest
解题:
简单模拟下旋转就好。
代码:
#include <iostream>using namespace std;int m1[31][31],m2[31][31],m3[31][31],m4[31][31],m5[31][31];int main(){int ans,cnt1,cnt2,cnt3,cnt4;int n;while(cin>>n&&n){cnt1=cnt2=cnt3=cnt4=0;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)cin>>m1[i][j];}for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)cin>>m2[i][j];}for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)m3[j][i]=m2[i][n-j+1];}for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)m4[j][i]=m3[i][n-j+1];}for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)m5[j][i]=m4[i][n-j+1];}for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(m2[i][j]==m1[i][j])cnt1++; if(m3[i][j]==m1[i][j])cnt2++; if(m4[i][j]==m1[i][j])cnt3++; if(m5[i][j]==m1[i][j])cnt4++;}}ans=cnt1;if(cnt2>ans)ans=cnt2;if(cnt3>ans)ans=cnt3;if(cnt4>ans)ans=cnt4;cout<<ans<<endl;}return 0;}
0 0
- HDU 4772 Zhuge Liang's Password (简单模拟题)
- HDU 4772 Zhuge Liang's Password(模拟水)
- hdu 4772 Zhuge Liang's Password【模拟】水题
- hdu 4772 Zhuge Liang's Password
- Hdu 4772 Zhuge Liang's Password
- HDU 4772 Zhuge Liang's Password
- HDU 4772 --Zhuge Liang's Password
- hdu 4772 Zhuge Liang's Password(水题)
- hdu:4772 Zhuge Liang's Password
- hdu 4772 Zhuge Liang's Password
- hdu 4772 Zhuge Liang's Password
- HDU-4772-Zhuge Liang's Password
- HDU 4772 Zhuge Liang's Password 水
- HDU 4772 Zhuge Liang's Password
- HDU 4772 Zhuge Liang's Password
- HDU 4772 Zhuge Liang's Password
- HDU 4772 Zhuge Liang's Password
- 7_11_C题 Zhuge Liang's Password(模拟)
- hadoop2.4.1伪分布式搭建
- shell语法简介
- poj 2823 单调队列 deque写法
- 有太多的东西要学
- #1127 : 二分图三·二分图最小点覆盖和最大独立集
- HDU 4772 Zhuge Liang's Password (简单模拟题)
- 项目加载不进去tomcat
- Complaints for Summer Vacation
- TOMCAT多站点配置
- wminotify.dll 病毒清理方法
- gsp页面标签
- 专业网站和数据下载主页收藏
- 《赠邻女》--唐·鱼玄机
- iOS- CoreData 数据库管理利器!