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/Others)
Total Submission(s): 59 Accepted Submission(s): 47
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
1 2
3 4
5 6
7 8
2
10 20
30 13
90 10
13 21
0
2
水题。。。
写个函数进行旋转就可以了。
/* ***********************************************
Author :kuangbin
Created Time :2013-11-9 12:44:06
File Name :E:\2013ACM\专题强化训练\区域赛\2013杭州\1003.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; const int MAXN = ;
int a[MAXN][MAXN];
int b[MAXN][MAXN];
int n;
void change()
{
int c[MAXN][MAXN];
for(int i = ;i < n;i++)
for(int j = ;j < n;j++)
{
c[i][j] = a[n--j][i];
}
for(int i = ;i < n;i++)
for(int j = ;j < n;j++)
a[i][j] = c[i][j];
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d",&n) == && n)
{
for(int i = ;i < n;i++)
for(int j = ;j < n;j++)
scanf("%d",&a[i][j]);
for(int i = ;i < n;i++)
for(int j = ;j < n;j++)
scanf("%d",&b[i][j]);
int ans = ;
for(int k = ;k < ;k++)
{
int cnt = ;
for(int i = ;i < n;i++)
for(int j = ;j < n;j++)
if(a[i][j] == b[i][j])
cnt++;
ans = max(ans,cnt);
change();
}
printf("%d\n",ans);
}
return ;
}
HDU 4772 Zhuge Liang's Password (2013杭州1003题,水题)的更多相关文章
- HDU 4772 Zhuge Liang's Password (简单模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...
- HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4788 Hard Disk Drive (2013成都H,水题)
Hard Disk Drive Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 4788 Hard Disk Drive (2013成都H,水题) 进位换算
#include <stdio.h> #include <algorithm> #include <string.h> #include<cmath> ...
- 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 ...
- 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 ...
- 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 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 4770 Lights Against Dudely (2013杭州赛区1001题,暴力枚举)
Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- 解决tomcat下面部署多个项目log4j的日志输出会集中输出到一个项目中的问题
在一次项目上线后,发现了一个奇怪的问题,经过对源码的阅读调试终于解决,具体经过是这样的: 问题描述:tomcat7下面部署多个项目,log4j的日志输出会集中输出到一个项目中,就算配置了日志文件的绝对 ...
- 第11月第11天 avplayer循环播放
1. /* Setting actionAtItemEnd to None prevents the movie from getting paused at item end. A very sim ...
- 2017/05/21 java 基础 随笔
工具类:所有的方法都是静态的,如果一个类中所有的方法都是静态的,需要再多做一步,私有构造方法,不让其他类创建本类对象. 生成文档: java.lang 包不用导入 常见代码块的应用 * a:局部 ...
- MySQL5.6快速安装【转】
下载MySQL5.6 访问MySQL官网 点击Downloads,然后选择Archives 选择MySQL Community Server 选择合适版本和平台 选择下载预先编译好的二进制安装包 将下 ...
- C#排队处理DEMO
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 解决C/C++语言中全局变量重复定义的问题
前言 今天,在整理自己的代码的时候,考虑到我写的代码从一至终都是在一个cpp文件里面.于是,想把自己的代码中的各个模块分离开来,以便更好地阅读和管理. 遇到的问题 我的做法是: 宏定义.结构体定义.函 ...
- Java 在方法和作用域内的内部类
通常,如果所读写 的代码包含了内部类,那么它们都是"平凡的"内部类,简单并且容易理解,然而,内部类的语法覆盖了大量其它的更加难以理解的计数,例如可以在一个方法里或者在任意的作用域里 ...
- PHP获取客户端的IP地址
首先我们来了解相关变量的含义: $_SERVER['REMOTE_ADDR']:浏览当前页面的用户计算机的ip地址 $_SERVER['HTTP_CLIENT_IP']:客户端的ip $_SERVER ...
- metasploit利用漏洞渗透攻击靶机
1.网络测试环境构建 首先需要先配置好一个渗透测试用的网络环境,包括如图1所示的运行Kali Linux系统的计算机,如图2所示的老师给的Windows Server 2000系统的计算机.这两台计算 ...
- React 中 context 的使用
官方文档说明(英) 看了别人写的中文博客,再看了官方英文文档,发现还是官方文档讲的浅显易懂一些,看了之后,半翻译半理解地写了这篇博客,更易于新手理解. 介绍 context 是在 react @ 0. ...