HDU 4772 Zhuge Liang ' s Password (simple simulation questions)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4772


Surface:

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 is the most famous and smart military leader. He enemy was Sima Yi, the military leader of Kingdom Wei. Sima Yi always looked stupid when fighting against Zhuge Liang. But it is 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 is a big problem. Zhuge Liang invented a kind of bull-like or horse-like robot called "Wooden Bull & Floating Horse" (in abbreviation, WB FH) 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 is always worrying on everything and always does trivial things by himself. Since Ma Su lost jieting and is killed by him, he didn ' t trust anyone ' s IQ no more. He thought the soldiers might forget the password of WBFHS. So he made the password cards for each WBFH. If the soldier operating a WBFH forgot the password or got killed, the password still could is regained by those-PASSW Ord 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 "the"-the-password by-cards. He said to Sima Yi:
"A password card is a square grid consisting of nxn cells. In each cell,there is a number. The password cards is of the same size. If you overlap them, you get both numbers in each cell. Those-numbers in a cell is the same or not the same. You can turn a card by 0 degree, degrees, degrees, or + degrees, and then overlap it on another. But flipping was not allowed. The maximum amount of cells which contains, equal numbers after overlapping, is the password. Please note that the cards must is totally overlapped. You can ' t only overlap a part of them. "
Now you should find a-a-to-figure out the password for each WBFH as quickly as possible.
Input There is several test cases.
In each test case:
The first line contains a integer N, meaning the password card is a nxn grid (0<n<=30).
Then a nxn matrix follows, describing a password card. Each element was an integer in a cell.
Then another nxn matrix follows, describing another password card.
Those integers is 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

Source2013 Asia Hangzhou Regional Contest

Solving:
It's good to spin under a simple simulation.

Code:
#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;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4772 Zhuge Liang ' s Password (simple simulation questions)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.