HDU4772(杭州赛区)

Zhuge Liang‘s Password

Time 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 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

Source

2013 Asia Hangzhou Regional Contest

题意:给你两个n*n的矩阵,任意翻转一个矩阵0,90,180,270度,与另一个矩阵重叠,求重叠的最大数字是多少

求出坐标变换公式就行c[i][j] = a[n-j][i],相当于每次将矩阵逆置一次

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
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<<ans<<endl;
    }
}
时间: 2024-10-12 08:18:51

HDU4772(杭州赛区)的相关文章

2013ACM-ICPC杭州赛区全国邀请赛——Random Walk

题目链接 题意: n个点,按照题中给的公式可以求出任意两个点转移的概率.求从1到n的期望转移次数 分析: 设dp[i]为从i到n的期望,那么可以得到公式dp[i] = sigma(dp[i + j] * p(i + j, i)),1 <= j <= m 把这个式子展开来:dp[i - m] * p(i - m, i) + dp[i - m + 1] * dp(i - m + 1, i) + ... + dp[i] * p(i, i) + ... + dp[i + m] * p(i + m, i

Hdu4771(杭州赛区)

Stealing Harry Potter's Precious Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1875    Accepted Submission(s): 878 Problem Description Harry Potter has some precious. For example, his invisib

HDU 4458 Shoot the Airplane (2012年杭州赛区现场赛F题)

1.题目描述:点击打开链接 2.解题思路:本题利用运动的相对性解决.可以假设飞机固定不动,那么子弹相当于还有一个水平分量,只不过方向是-v.这样,问题就转化为一个动点什么时候到达一个多边形内部的问题了.不过本题有一个细节就是g可能等于0,因此要分匀变速运动和匀速运动2种情况求出最大可能的子弹飞行时间.另外一个细节就是本题对精度要求比较高,建议判断点是否在线段上改为利用坐标的差值来判断,避开使用Dot函数. 3.代码: #include<iostream> #include<algorit

hdu 4462 第37届ACM/ICPC 杭州赛区 J题

题意:有一块n*n的田,田上有一些点可以放置稻草人,再给出一些稻草人,每个稻草人有其覆盖的距离ri,距离为曼哈顿距离,求要覆盖到所有的格子最少需要放置几个稻草人 由于稻草人数量很少,所以状态压缩枚举,之后慢慢判断即可,注意放稻草人的格子是不需要覆盖的 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath>

hdu 4461 第37届ACM/ICPC杭州赛区I题

题意:给两个人一些棋子,每个棋子有其对应的power,若b没有或者c没有,或者二者都没有,那么他的total power就会减1,total power最少是1,求最后谁能赢 如果b或c出现的话,flag就标记为1,那么在判断的时候如果flag==0,就说明他们没出现过,那么就要-1,然后就wa了,必须要两个变量判断,不知道为什么 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #inclu

hdu 4463 第37届ACM/ICPC杭州赛区K题 最小生成树

题意:给坐标系上的一些点,其中有两个点已经连了一条边,求最小生成树的值 将已连接的两点权值置为0,这样一定能加入最小生成树里 最后的结果加上这两点的距离即为所求 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map>

HDU 4455 Substrings (2012年杭州赛区现场赛C题)

1.题目描述:点击打开链接 2.解题思路:本题利用dp解决.不过这个dp的思路的确比太容易想到.需要观察规律才能发现.我们可以从贡献值的角度考虑.以题目中给的样例来说明这种方法. 通过观察相邻两个w值,我们会发现一个事实:每个大区间都包含了小区间的解(这里的解即原题中的sum值).但是这还不够,观察图上标记为红色的数字,它们可以看做是上一个w值对应的区间多出来的新数字,如果我们可以算出这些红色数字的贡献值,那么我们就能得到当前w下的解.那么该如何计算呢? 继续观察后会发现,每次w增加1,区间个数

hdu 4738 2013杭州赛区网络赛 桥+重边+连通判断 ***

题意:有n座岛和m条桥,每条桥上有w个兵守着,现在要派不少于守桥的士兵数的人去炸桥,只能炸一条桥,使得这n座岛不连通,求最少要派多少人去. 处理重边 边在遍历的时候,第一个返回的一定是之前去的边,所以这条边忽略,然后继续遍历,此时可以通过未遍历的边返回pre 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath

HDU 4462 Scaring the Birds (2012年杭州赛区现场赛J题)

1.题目描述:点击打开链接 2.解题思路:本题是一道简单模拟题.不过重点还是对于题目细节的理解.容易犯2个理解错误:(1)误以为是每个稻草人有不同的scaring range,实际上scaring range是由不同的vacant intersection决定的,跟稻草人毫无关系.(2)误以为所有点都需要被覆盖,实际上题目要求的是只要所有corn被保护就行,插稻草人的地方本来就是空地,有没有被保护无所谓的.由于题目给的范围非常小,完全可以通过枚举集合来确定哪些位置需要稻草人,如果这些稻草人成功的