HDU 4772 Zhuge Liang's Password (简单模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772
题面:
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
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.
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
解题:
简单模拟下旋转就好。
代码:
#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;
}
HDU 4772 Zhuge Liang's Password (简单模拟题)的更多相关文章
- HDU 4772 Zhuge Liang's Password (2013杭州1003题,水题)
Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- 2019浙大校赛--A--Thanks, TuSimple!(简单模拟题)
这题前三段都是一堆吹爆赞助商的屁话,正式题目在图片下边,一个简单模拟题. 题目大意: 有n个男生,m个女生在进行舞会,其中一部分男生祥和比自己矮的女生跳舞,一部分男生想和比自己高的女生跳舞,一部分女生 ...
- hdu 4739 Zhuge Liang's Mines (简单dfs)
Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 4739 Zhuge Liang's Mines 随机化
Zhuge Liang's Mines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...
- HDOJ 4739 Zhuge Liang's Mines
Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 4048 Zhuge Liang's Stone Sentinel Maze
Zhuge Liang's Stone Sentinel Maze Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/327 ...
- HDU 4739 Zhuge Liang's Mines (2013杭州网络赛1002题)
Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- UVa 679 小球下落 简单模拟题,树
题目大意:给你一个完全二叉树,并且给他们编号,编号规则为左子树为2*k,右子树为2*k+1,每一个节点 上都有一个开关,初始时开关都处于关闭状态,小球碰到节点就会改变该点的开关的状态.然后给你I个小球 ...
- POJ 1008 简单模拟题
e.... 虽然这是一道灰常简单的模拟题.但是米做的时候没有读懂第二个日历的计时方法.然后捏.敲完之后华丽的WA了进一个点.坑点就在一年的最后一天你是该输出本年的.e ...但是我好想并没有..看di ...
随机推荐
- 转:MVVM的基本入门简介
https://mp.weixin.qq.com/s?__biz=MzA3MjA4NjE3NQ==&mid=404502568&idx=1&sn=fe512f9820b99d3 ...
- [PWA] Disable Text Selection and Touch Callouts in a PWA on iOS
Because an installed PWA is really just a web app running in a browser, there are some browser behav ...
- Linux下的各文件夹的作用(转)
linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基 ...
- Android学习(二十三)SubMenu 子菜单
一.SubMenu子菜单 和功能菜单相似,但是可以添加子菜单. 二.实现步骤: 1.通过onCreateOptionsMenu方法创建子菜单,可以通过代码动态创建,也可以通过xml进行创建. 2.通过 ...
- STL学习笔记(序列式容器)
Vector Vector是一个动态数组. 1.Vector的操作函数 构造.拷贝和析构 vector<Elem> c //产生一个空vector ,其中没有任何元素 vector< ...
- C# 反编译工具
justdecompile http://down.51cto.com/data/2067031 ILSpy http://www.fishlee.net/soft/ilspy_chs/
- layer 不居中的坑爹问题
使用了该代码弹出一个图片.但居然不居中 var layer_index = layer.open({ type: 1, title: false, closeBtn: 0, area: '516px' ...
- linux rm -rf * 文件恢复记
手太快,肠子都毁清了.本来是删除一个文件 rm path/myfile.txt结果不知为何加了个*,变成了rm path/myfile.txt *赶紧ls,发现所有代码都化为了乌有,还没提交,还没备份 ...
- junit测试时报No runnable methods错误的解决方法
1.因为你@Test时import的是@org.testng.annotations.Test所以会报错 解决方法:改为import org.junit.Test;就可以了
- 《TomCat与Java Web开发技术详解》(第二版) 第六章节对应CD附带的helloapp无法启动的问题解决
首先记录一下如何解决此章节CD中附带的helloapp无法启动的问题 我用的tomcat版本是:7.0.47:为了便于控制,针对此章节的helloapp,我在tomcat/conf/Catalina/ ...