hdu5926Mr. Frog’s Game
Mr. Frog’s Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1300 Accepted Submission(s): 639
In this game, if you can draw at most three horizontal or vertical head-and-tail-connected lines over the empty grids(the lines can be out of the whole board) to connect two non-empty grids with the same symbol or the two non-empty grids with the same symbol
are adjacent, then you can change these two grids into empty and get several more seconds to continue the game.
Now, Mr. Frog starts a new game (that means there is no empty grid in the board). If there are no pair of grids that can be removed together,Mr. Frog will say ”I’m angry” and criticize you.
Mr. Frog is battle-scarred and has seen many things, so he can check the board in a very short time, maybe one second. As a Hong Kong Journalist, what you should do is to check the board more quickly than him, and then you can get out of the room before Mr.
Frog being angry.
which indicates the number of test cases.
For each test case, the first line contains two integers n and m (1≤n,m≤30).
In the next n lines, each line contains m integers, j-th number in the i-th line means the symbol on the grid(the same number means the same symbol on the grid).
You should output “Case #x: y”,where x is the case number(starting from 1), and y is a string representing the answer of the question. If there are at least one pair of grids that can be removed together, the y is “Yes”(without quote), else y is “No”.
3 3
1 2 1
2 1 2
1 2 1
3 3
1 2 3
2 1 2
3 2 1
Case #2: No
first sample can be explained as below.
思路:暴力模拟,考虑边上跟相邻两种情况。
#include<iostream>
#include<map>
using namespace std;
int a[35][35];
map<int,int> mp;
int n,m;
bool check(int i,int j)
{
if(i>=1&&i<=n&&j>=1&&j<=m) return true;
return false;
}
int main()
{
int T;
cin>>T;
int flag;
for(int cas=1;cas<=T;cas++)
{
flag=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
mp.clear();
for(int j=1;j<=m;j++)
{
mp[a[1][j]]++;
if(mp[a[1][j]]>=2)
{
cout<<"Case #"<<cas<<": Yes"<<endl;
flag=1;
}
if(flag) break;
}
if(flag) continue;
mp.clear();
for(int j=1;j<=m;j++)
{
mp[a[n][j]]++;
if(mp[a[n][j]]>=2)
{
cout<<"Case #"<<cas<<": Yes"<<endl;
flag=1;
}
if(flag) break;
}
if(flag) continue;
mp.clear();
for(int i=1;i<=n;i++)
{
mp[a[i][1]]++;
if(mp[a[i][1]]>=2)
{
cout<<"Case #"<<cas<<": Yes"<<endl;
flag=1;
}
if(flag) break;
}
if(flag) continue;
mp.clear();
for(int i=1;i<=n;i++)
{
mp[a[i][m]]++;
if(mp[a[i][m]]>=2)
{
cout<<"Case #"<<cas<<": Yes"<<endl;
flag=1;
}
if(flag) break;
}
if(flag) continue;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(check(i,j+1)&&a[i][j]==a[i][j+1]) flag=1;
if(check(i+1,j)&&a[i][j]==a[i+1][j]) flag=1;
if(flag) break;
}
if(flag) break;
}
if(flag) {cout<<"Case #"<<cas<<": Yes"<<endl;continue;}
cout<<"Case #"<<cas<<": No"<<endl;
}
return 0;
}
hdu5926Mr. Frog’s Game的更多相关文章
- [LeetCode] Frog Jump 青蛙过河
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- hdu5037 Frog (贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=5037 网络赛 北京 比较难的题 Frog Time Limit: 3000/1500 MS (Java/Othe ...
- CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&&当然暴力is also no problem)
C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- POJ 1054 The Troublesome Frog
The Troublesome Frog Time Limit: 5000MS Memory Limit: 100000K Total Submissions: 9581 Accepted: 2883 ...
- Leetcode: Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- hdu 4004 The Frog's Games
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...
- HDU 5578 Friendship of Frog 水题
Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- Eat that Frog
Eat that Frog,中文翻译过来就是“吃掉那只青蛙”.不过这里并不是讨论怎么去吃青蛙,而是一种高效的方法. Eat that Frog是Brian Tracy写的一本书(推荐阅读).这是一个很 ...
随机推荐
- 选学霸(codevs 3372)
题目描述 Description 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一部分没有,同学们就会抗议.所以老师想请你帮他求出他该选多少学霸,才能既不让同 ...
- PHP PDO使用
PHP操作MySQL数据库方式有三种: *1. mysql 最原始的.纯过程化的 如连接: mysql_connect(主机名,账号,密码); 2. mysqli 改进版的.兼容过程化和面向对象化操作 ...
- [52ABP系列] - 001、SPA免费项目模版搭建教程
前言 这个项目是基于 ABP ASPNetCore 免费版,整合 NG-Alian 和 NG-Zorro 的项目,所以比较适合熟悉 ABP 和 Angular2+ 的开发人员, 如果你是新手,学习的话 ...
- oralce之复杂查询举例
表结构: S(SNO,SNAME) 代表 学号.学生姓名: C(CNO,CNAME,CTEACHER) 代表 课号,课程名称.授课老师 SC(SNO,CNO,SCGRADE) 代表 学号.课号.课程成 ...
- formData 对象
(1)创建的formData打印为空? var edition=$("#edinum").val();//版本号 var uploader=$("#upman" ...
- 在HDInsight中从Hadoop的兼容BLOB存储查询大数据的分析
在HDInsight中从Hadoop的兼容BLOB存储查询大数据的分析 低成本的Blob存储是一个强大的.通用的Hadoop兼容Azure存储解决方式无缝集成HDInsight.通过Hadoop分布式 ...
- HDU 1226 超级password
跟POJ 1465 multiple 类是.仅仅只是多了2个条件,长度不能超过500.还有就是 可能不是十进制. bfs+同余定理,就是用 mod 来判重. G++ 15ms 每次枚举一位,然后记录下 ...
- Python的lambda函数与排序
Python的lambda函数与排序 2010-03-02 15:02 2809人阅读 评论(0) 收藏 举报 lambdapythonlistlispclass工作 目录(?)[+] 前几天 ...
- 2.eclipse 插件安装烦死人(2)
安装插件的实际结果是:(烦死人),要不是很多插件找不到,要不就是版本不对,要不就是下载了装上没有效果,要不就是在线安装(速度爆慢),好不容易等到结果了,结果是些错…… 最后我的eclipse 3.5. ...
- exception log
except Exception as e: l = [str(i) for i in [dbid, f_mp3, e]] log_s = '||'.join(l) logging.exception ...