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写的一本书(推荐阅读).这是一个很 ...
随机推荐
- bzoj1052 [HAOI2007]覆盖问题 - 贪心
Description 某人在山上种了N棵小树苗.冬天来了,温度急速下降,小树苗脆弱得不堪一击,于是树主人想用一些塑料薄膜把这些小树遮盖起来,经过一番长久的思考,他决定用3个L*L的正方形塑料薄膜将小 ...
- 【51NOD1766】树上的最远点对(线段树,LCA,RMQ)
题意:n个点被n-1条边连接成了一颗树,给出a~b和c~d两个区间, 表示点的标号请你求出两个区间内各选一点之间的最大距离,即你需要求出max{dis(i,j) |a<=i<=b,c< ...
- msp430入门编程06
msp430中C语言的程序结构06 msp430中C语言的函数及实现07 msp430中C语言操作端口I/O10 msp430中C语言的模块化头文件及实现11 msp430中C语言的模块化头文件及库文 ...
- Same Tree (二叉树DFS)
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- Orcle定时生成表数据作业
--建表 create table table41( id ) not null, --主键 col1 ), col2 ), col3 ), col4 int, col5 timestamp, col ...
- 【CV论文阅读】Image Captioning 总结
初次接触Captioning的问题,第一印象就是Andrej Karpathy好聪明.主要从他的两篇文章开始入门,<Deep Fragment Embeddings for Bidirectio ...
- ubuntu11.04 编译ffmpeg2.7 并生成 ffplay进行流媒体測试
源代码安装方式: 1. 先下载ffmpeg 安装包 到官网上 http://ffmpeg.org/download.html#releases 下载.选择Download gzip tarball. ...
- kvm虚拟化网络管理
Linux Bridge 网桥管理 VM2 的虚拟网卡 vnet1 也连接到了 br0 上. 现在 VM1 和 VM2 之间可以通信,同时 VM1 和 VM2 也都可以与外网通信 # Vlan LAN ...
- MariaDB 数据库的备份
1> 备份单个数据库 mysqldump -uroot -plichao123 --database students1 > stundents.sql; 2>查看备份文件 3> ...
- 背包系统学习笔(tu)记(cao)
这几天在学习背包系统,网上有看到一个挺牛逼的背包系统,不过人家那个功能很全面,一个背包系统就囊括了装备,锻造,购买等等功能(这里给出网址:https://blog.csdn.net/say__yes/ ...