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. hdu - 2066 一个人的旅行(基础最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=2066 把与草儿相连的城市最短距离置为0,然后进行dijkstra,在t个城市里找出距离最近的一个即可. #inc ...

  2. 使用idea编译spring-framework5.0源码

    自从迈入java开发这个行当,从来没有好好的研究过源码,深感惭愧,话不多说,今天上一篇使用idea编译spring5.0源码. 以下在win中构建和编译过程分为 jdk环境的配置 gradle的下载和 ...

  3. 简谈Java传值传引用

    本随笔旨在强化理解传值与传引用   如下代码的运行结果 其中i没有改变,s也没有改变. 但model中的值均改变了. i :100s :hellomodel :testchangemodel2 :ch ...

  4. SQL server 2008 添加,删除字段

    添加,刪除字段 如果要在数据表中添加一个字段,应该如何表示呢?下面就为您介绍表添加字段的SQL语句的写法,希望可以让您对SQL语句有更深的认识. 通用式: alter table [表名] add [ ...

  5. Kettle循环删除数据

    1.问题描述: 某个系统原库的数据同步到备份库.但是由于原库的的数据会物理删除,此时需要删除备份库的数据. 2.不理想的解决1: 1)首先从备份库获取该表的所有ID: 2)循环备份库的ID,去原库检测 ...

  6. 基于 Java 的开源网络爬虫框架 WebCollector

    原文:https://www.oschina.net/p/webcollector

  7. Codeforces Round #247 (Div. 2) B

    B. Shower Line time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. 条款二:最好使用c++转型操作符

    一.static_cast基本上拥有与c旧式转型相同的威力与意义,以及相同的限制,不能够移除表达式的常量性,const_cast负责这个功能 二.const_cast用来改变表达式中的常量性,如果将c ...

  9. AutoCAD如何倒角 倒圆角 倒直角

    倒圆角:输f 再输r 再输入你想倒的半径,然后选相邻的两边倒直角:输chamfer 再输d 再输你想倒的距离,然后先相邻的两边 祝你成功

  10. c#实例化继承类,必须对被继承类的程序集做引用 .net core Redis分布式缓存客户端实现逻辑分析及示例demo 数据库笔记之索引和事务 centos 7下安装python 3.6笔记 你大波哥~ C#开源框架(转载) JSON C# Class Generator ---由json字符串生成C#实体类的工具

    c#实例化继承类,必须对被继承类的程序集做引用   0x00 问题 类型“Model.NewModel”在未被引用的程序集中定义.必须添加对程序集“Model, Version=1.0.0.0, Cu ...