首页 > ACM题库 > HDU-杭电 > HDU 4772-Zhuge Liang’s Password-计算几何-[解题报告]HOJ
2015
09-17

HDU 4772-Zhuge Liang’s Password-计算几何-[解题报告]HOJ

Zhuge Liang’s Password

问题描述 :

  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.

输入:

  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

输出:

  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

样例输入:

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

样例输出:

0
2

题意:给你两个矩阵,一个矩阵旋转90度,180度,270度,

然后和另外一个矩阵进行比较,如果对应值相同,则加一,最后得出最大的值

题目没什么难度。。。。主要是纪念下。。。。貌似这一题是当时比赛前一个晚上做出来的

AC代码:

#include<iostream>
#include<cstdio>
using namespace std;
int a[31][31],b[31][31];
int main()
{
    int N;int i,j,m,n;
    while(scanf("%d",&N)!=EOF,N)
    {
        int cnt[5]={0};
        //cout<<1<<endl;
        for( i=1;i<=N;i++)
            for( j=1;j<=N;j++)
             scanf("%d",&a[i][j]);
        for( i=1;i<=N;i++)
            for( j=1;j<=N;j++)
             scanf("%d",&b[i][j]);
        for(i=1;i<=N;i++)
        {
            for(j=1;j<=N;j++)
            {
                if(a[i][j]==b[i][j])
                    cnt[1]++;
                if(a[N+1-j][i]==b[i][j])
                    cnt[2]++;
                if(a[N+1-i][N+1-j]==b[i][j])
                    cnt[3]++;
                if(a[j][N+1-i]==b[i][j])
                    cnt[4]++;
            }
            //cout<<-1<<endl;
        }
        int sum=0;
        for(i=1;i<=4;i++)
        {
            sum=max(sum,cnt[i]);
        }
        printf("%d\n",sum);
    }
}

参考:http://blog.csdn.net/k183000860/article/details/41726133