HDU4772 (Hangzhou Division)
Zhuge Liang's PasswordTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1120 Accepted Submission (s): 768
Problem Description In the specified ent 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 sans ss 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 specified Ted 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 wocould 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 cocould be regained by those two password cards.
Once, Sima Yi defeated Zhuge Liang again, and got implements 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 x N grid (0 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
Question: Give you two n * n matrices. Flip a matrix of 0, 90, 180,270 degrees at will, overlap with another matrix, and find the maximum number of overlapping digits.
Obtain the coordinate transformation formula. c [I] [j] = a [n-j] [I] is equivalent to setting the matrix inverse once each time.
#include #include
#include
#include
using namespace std;int a[35][35];int b[35][35];int c[35][35];int n,m;void fanzhuan(){ for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { c[i][j] = a[n-j+1][i]; } for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { a[i][j] = c[i][j]; }}int main(){#ifdef xxz freopen("in.txt","r",stdin);#endif while(cin>>n && n) { for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) cin>>a[i][j]; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) cin>>b[i][j]; int ans = 0; int cent = 0; for(int i = 0; i <4; i++) { cent = 0; for(int j = 1; j <= n; j++) { for(int k = 1; k <= n; k++) { if(a[j][k] == b[j][k]) cent++; } } ans = max(cent,ans); fanzhuan(); } cout<