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;
}
}

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

  1. HDU 4777 Rabbit Kingdom (2013杭州赛区1008题,预处理,树状数组)

    Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. HDU 4778 Gems Fight! (2013杭州赛区1009题,状态压缩,博弈)

    Gems Fight! Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)T ...

  3. HDU 4771 Stealing Harry Potter's Precious (2013杭州赛区1002题,bfs,状态压缩)

    Stealing Harry Potter's Precious Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  4. HDU 4770 Lights Against Dudely (2013杭州赛区1001题,暴力枚举)

    Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. hdu 4741 2013杭州赛区网络赛 dfs ***

    起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...

  6. hdu 4739 2013杭州赛区网络赛 寻找平行坐标轴的四边形 **

    是平行坐标轴的,排个序搞一下就行了,卧槽,水的不行 如果不是平行的,则需要按照边长来判断

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

    题意:有n座岛和m条桥,每条桥上有w个兵守着,现在要派不少于守桥的士兵数的人去炸桥,只能炸一条桥,使得这n座岛不连通,求最少要派多少人去. 处理重边 边在遍历的时候,第一个返回的一定是之前去的边,所以 ...

  8. hdu 4412 2012杭州赛区网络赛 期望

    虽然dp方程很好写,就是这个期望不知道怎么求,昨晚的BC也是 题目问题抽象之后为:在一个x坐标轴上有N个点,每个点上有一个概率值,可以修M个工作站, 求怎样安排这M个工作站的位置,使得这N个点都走到工 ...

  9. hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***

    题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙,          每个逮捕队伍在每个城市可以选 ...

随机推荐

  1. quartz在application中的使用

    项目结构图: TestMain.java package com; import org.quartz.Scheduler; import org.quartz.impl.StdSchedulerFa ...

  2. citySelect省市区jQuery联动插件

    参考地址:http://blog.csdn.net/qq_33556185/article/details/50704446 参考地址:http://www.lanrenzhijia.com/jque ...

  3. Windows 2012 安装 Oracle 11g 报错:[INS-13001]环境不满足最低要求。

    问题: 在Windows Server 2012 安装上 Oracle 11g 时,安装程序报错:[INS-13001]环境不满足最低要求. 分析原因: Oracle 在发布 11g时,Winodws ...

  4. linux POSIX 信号量介绍

    信号量一.什么是信号量信号量的使用主要是用来保护共享资源,使得资源在一个时刻只有一个进程(线程)使用.多线程可以同时运行多个线程函数完成功能,但是对于共享数据如果不加以锁定,随意改变共享数据的值会发生 ...

  5. mysql 5.6 在线 DDL

    原文链接地址:http://seanlook.com/2016/05/24/mysql-online-ddl-concept/ 做MySQL的都知道,数据库操作里面,DDL操作(比如CREATE,DR ...

  6. HDU 5988 Coding Contest(费用流+浮点数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988 题目大意: 给定n个点,m条有向边,每个点是一个吃饭的地方,每个人一盒饭.每个点有S个人,有B盒 ...

  7. python 全栈开发,Day70(模板自定义标签和过滤器,模板继承 (extend),Django的模型层-ORM简介)

    昨日内容回顾 视图函数: request对象 request.path 请求路径 request.GET GET请求数据 QueryDict {} request.POST POST请求数据 Quer ...

  8. WebService简介-02

    WebService-面向服务编程SOA WebService-远程通信 运行效果: 1:添加服务器引用http://www.webxml.com.cn/WebServices/WeatherWebS ...

  9. SpringMVC的初始

    1:其实一开始对SSH和SSM并不是很熟悉的,对SSH可能熟悉些(Struts,Spring,Hibernate)这三个框架.但是由于框架的更新,和出现了更好的框架,一些老框架就被淘汰了,但是呢,一些 ...

  10. 《Gradle权威指南》--Java Gradle插件

    No1: dependencies{ compile group: 'com.squareup.okhttp3',name:'okhttp',version:'3.0.1' } //缩写 depend ...