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


Problem Description
One day, Mr. Frog is playing Link Game (Lian Lian Kan in Chinese).



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.
 

Input
The first line contains only one integer T (T≤500),
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).
 

Output
For each test case, there should be one line in the output.

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”.
 

Sample Input

2
3 3
1 2 1
2 1 2
1 2 1
3 3
1 2 3
2 1 2
3 2 1
 

Sample Output

Case #1: Yes
Case #2: No

Hint

first sample can be explained as below.

 

Source

思路:暴力模拟,考虑边上跟相邻两种情况。

#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的更多相关文章

  1. [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 ...

  2. hdu5037 Frog (贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=5037 网络赛 北京 比较难的题 Frog Time Limit: 3000/1500 MS (Java/Othe ...

  3. 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 ...

  4. Frog Jump

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  5. POJ 1054 The Troublesome Frog

    The Troublesome Frog Time Limit: 5000MS Memory Limit: 100000K Total Submissions: 9581 Accepted: 2883 ...

  6. 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 ...

  7. hdu 4004 The Frog's Games

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...

  8. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  9. Eat that Frog

    Eat that Frog,中文翻译过来就是“吃掉那只青蛙”.不过这里并不是讨论怎么去吃青蛙,而是一种高效的方法. Eat that Frog是Brian Tracy写的一本书(推荐阅读).这是一个很 ...

随机推荐

  1. JS基础:函数

    函数声明和函数表达式 在 JS 中定义函数的方式有两种:一种是函数声明,一种是函数表达式. 例如: //函数声明 function fun() { ... } //函数表达式 var f = func ...

  2. Linux下汇编语言学习笔记42 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  3. MU Puzzle HDU - 4662

    Suppose there are the symbols M, I, and U which can be combined to produce strings of symbols called ...

  4. [bzoj3252]攻略_dfs序_线段树_贪心

    攻略 bzoj-3252 题目大意:给定一棵n个节点的有根树,点有点权.让你选出至多k个节点,使得他们到根的链的并最大. 注释:$1\le n\le 2\cdot 10^5$,$1\le val_i\ ...

  5. 所有的异常都要使用try catch 语句捕获?

    在开发应用程序过程中必须检测代码可能发生的错误并进行正确的处理,这个在理想的情况下,应用程序中的每行 代码都按照预想的执行,要用到的每种资源总是可以利用,但是在实际的开发过程中,写代码难免会出错,或是 ...

  6. Spring Boot实现跨域(转)

    一.方法: 服务端设置Respone Header头中Access-Control-Allow-Origin 配合前台使用jsonp 继承WebMvcConfigurerAdapter 添加配置类 二 ...

  7. Java高级教程:Java并发性和多线程

    Java并发性和多线程: (中文,属于人工翻译,高质量):http://ifeve.com/java-concurrency-thread-directory/ (英文):http://tutoria ...

  8. how to read openstack code : wsgi

    要读懂本篇,你至少得写过一个python的web程序,并且把它部署到web服务器上过. 什么是wsgi 假设你写了一个python的web程序,并部署到了nginx上,那么一个http request ...

  9. 通过ICursor对Table进行操作(添加、修改、删除)

    通过ICursor对Table进行操作(添加.修改.删除) 2010-03-16 16:07:37|  分类: 工作|举报|字号 订阅 来自:http://blog.163.com/liuyang12 ...

  10. MySQL 高可用架构在业务层面的分析研究

    )读多写少 虚线表示跨机房部署,比方电子商务系统.一个Master既有读也有些写.对读数据一致性须要比較重要的.读要放在Master上面. M(R)仅仅是一个备库.仅仅有M(WR)挂了之后,才会切换到 ...