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写的一本书(推荐阅读).这是一个很 ...
随机推荐
- [K/3Cloud] 在设计时复制已有表单菜单或菜单项快速建立菜单
1.打开已有表单XML,找到FormAppearance的Menu节点,按Ctrl+C复制 <Appearances> <FormAppearance ElementType=&qu ...
- 【ZJOI2017 Round1练习】D8T3 stone(Nim游戏)
题意: 思路:与其类似的题是HDU5996 HDU5996为判定性问题,稍加改动就可以用来统计方案数 ..]of longint; v,cas,i,j,ans,tmp,n,s,k:longint; b ...
- 转载:C/C++检测内存泄漏的工具 vld Visual Leak Detector223 的使用方法和sample示例
这类的工具有 比如 :LeakDiag leakfinder "Visual Leak Detector" vld可以从http://vld.codeplex.com/releas ...
- Memcached集群之通过Repcached实现主从复制(待实践)
暂时了解有这东西,不搭建了. Mamcached可以通过Repcached实现主从复制.有以下优缺点: 优点: 1.能够实现Cache的冗余功能 2.主从之间可以互相读写(亮点) 参考: http:/ ...
- Python学习系列之装饰器
装饰器的作用 装饰器用于装饰某个函数.方法或者类,它可以让这个函数执行之前或者执行之后做一些操作 手工实现一个装饰器 def outer(some_func): #装饰器 $1 def inner() ...
- hadoop 文件操作
Create a directory in HDFS - mkdir The hadoop mkdir command is for creating directories in the hdfs. ...
- webpack-入口篇
入口起点[Entry Points]: 单个入口(简写)语法 用法:entry: string|Array<string> 例子(webpack.config.js) const conf ...
- UML——用例图
用例图是在需求分析阶段开发人员和用户对需求规格达成的某种共识.它描写叙述了待开发系统的功能需求. UML视频使我们对用例图的基本组成元素.属性.粒度等有了理论上的理解,我们还须要自己亲自己主动手画一画 ...
- python爬虫【第2篇】【多进程】
一.多进程 1.fork方法(os模块,适用于Lunix系统) fork方法:调用1次,返回2次.原因:操作系统经当前进程(父进程)复制出一份进程(子进程),两个进程几乎完全相同,fork方法分别在父 ...
- UM九图
UML有9种图: 用例图类图对象图状态图序列图协作图活动图组件图部署图 9,在中国是个阳数,通常代表很多的意思.比如说,九九艳阳天,九死而不悔,成吉思汗对功臣的九罪而不罚,天上九头鸟地上湖北佬,等等. ...