HDU4772 2013 Asia Hangzhou Regional Contest C Zhuge Liang's Password
2014-07-25 15:06
447 查看
Zhuge Liang's Password
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 621 Accepted Submission(s): 423
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固定一个不动,另一个旋转 0度, 90度, 180度 ,270度 求最大匹配
#include <iostream> #include <cstdio> #include <cstring> #define max(a,b) a > b ? a : b using namespace std; const int N = 31; int a ,b ,c ,d ,e ; void roll_90(int f[] ,int g[] ,int n) { for(int i=0;i<n;i++) for(int j=0;j<n;j++) g[j][n-1-i]=f[i][j]; } int main() { int n; while(cin>>n,n){ int s1=0,s2=0,s3=0,s4=0; for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>b[i][j]; if(b[i][j]==a[i][j]) s1++; } } roll_90(b,c,n); roll_90(c,d,n); roll_90(d,e,n); /*for(int i=0;i<n;i++){ for(int j=0;j<n;j++) cout<<c[i][j]<<" "; cout<<endl; } for(int i=0;i<n;i++){ for(int j=0;j<n;j++) cout<<d[i][j]<<" "; cout<<endl; } for(int i=0;i<n;i++){ for(int j=0;j<n;j++) cout<<e[i][j]<<" "; cout<<endl; }*/ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(a[i][j]==c[i][j]) s2++; if(a[i][j]==d[i][j]) s3++; if(a[i][j]==e[i][j]) s4++; } } int t1=max(s1,s2); int t2=max(s3,s4); int t3=max(t1,t2); cout<<t3<<endl; } return 0; }
相关文章推荐
- hdu4772 水题 Zhuge Liang's Password (2013 Asia Hangzhou Regional Contest problem C)
- HDU 4772 Zhuge Liang's Password(2013 Asia Hangzhou Regional Contest )
- HDU 4739 Zhuge Liang's Mines (2013 ACM/ICPC Asia Regional Hangzhou Online)
- 2013 Asia Hangzhou Regional Contest(HDU 4770 4771 4772 )
- hdu 4778 Gems Fight! 2013 Asia Hangzhou Regional Contest
- 2013 Asia Hangzhou Regional Contest bnuoj ID: 4771
- HDU 4770 Lights Against Dudely(2013 Asia Hangzhou Regional Contest A)
- 2013 Asia acm Hangzhou Regional Contest 杭州现场赛
- hdu4771 BFS Stealing Harry Potter's Precious (2013 Asia Hangzhou Regional Contest problem B)
- HDU 4770 Lights Against Dudely(2013 Asia Hangzhou Regional Contest)
- 2013 Asia Hangzhou Regional Contest
- hdu4770 暴力状压 Lights Against Dudely (2013 Asia Hangzhou Regional Contest problem A)
- HDU 4771 Stealing Harry Potter's Precious(2013 Asia Hangzhou Regional Contest )
- HDU4771(2013 Asia Hangzhou Regional Contest )
- hdu4771 Stealing Harry Potter's Precious 2013 Asia Hangzhou Regional Contest
- 2013 Asia Hangzhou Regional Contest--hdu4770Lights Against Dudely(DLX)
- 2013 Asia Hangzhou Regional Contest
- hdu 4739 Zhuge Liang's Mines 2013 ACM/ICPC Asia Regional Hangzhou Online
- 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)
- hdu 4781 Assignment For Princess && 2013 Asia Chengdu Regional Contest && YY