2013亚洲区域赛杭州站 B题 Zhuge Liang's Password

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

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
题目大意:给定两个n*n的矩阵,可以进行90度180度和270度旋转,求出二者最对的重合的数字,
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int a[35][35],a90[35][35],a180[35][35],a270[35][35],b[35][35];
int n;
void turn_90()
{
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
             a90[i][j]=a[n-1-j][i];
}
void turn_180()
{
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
          a180[i][j]=a[n-1-i][n-j-1];
}
void turn_270()
{
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
           a270[i][j]=a[j][n-1-i];
}
int main()
{
    while(~scanf("%d",&n))
    {
        if(n==0)
            break;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
               scanf("%d",&a[i][j]);
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
               scanf("%d",&b[i][j]);
        turn_90();
        /*for(int i=0;i<n;i++)
        {
           for(int j=0;j<n;j++)
            printf("%d ",a90[i][j]);
           printf("\n");
        }
        printf("--------\n");*/
        turn_180();
        /*for(int i=0;i<n;i++)
        {
           for(int j=0;j<n;j++)
            printf("%d ",a180[i][j]);
           printf("\n");
        }
        printf("--------\n");*/
        turn_270();/*
        for(int i=0;i<n;i++)
        {
           for(int j=0;j<n;j++)
            printf("%d ",a270[i][j]);
           printf("\n");
        }
        printf("--------\n");*/
        int cnt=0;
        int count=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(a[i][j]==b[i][j])
                   cnt++;
        count=max(count,cnt);
        cnt=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(a90[i][j]==b[i][j])
                   cnt++;
        count=max(count,cnt);
        cnt=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(a180[i][j]==b[i][j])
                   cnt++;
        count=max(count,cnt);
        cnt=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(a270[i][j]==b[i][j])
                   cnt++;
        count=max(count,cnt);
        printf("%d\n",count);
    }
    return 0;
}
/*
3
1 2 3
4 5 6
7 8 9

9 8 7
6 5 4
3 2 1
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值