hdu5926Mr. Frog’s Game
来源:互联网 发布:python 股票分析 教程 编辑:程序博客网 时间:2024/05/22 00:39
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.
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).
For each test case, the first line contains two integers n and m (
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”.
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
23 31 2 12 1 21 2 13 31 2 32 1 23 2 1
Sample Output
Case #1: YesCase #2: NoHintfirst sample can be explained as below.
Source
2016CCPC东北地区大学生程序设计竞赛 - 重现赛
思路:暴力模拟,考虑边上跟相邻两种情况。
#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;}
阅读全文
0 0
- hdu5926Mr. Frog’s Game
- [hdu] The frog's Game
- 【HDU 1005 Frog’s Game】
- HDU5926-Mr. Frog’s Game
- hdu4004 Frog’s Game【二分+贪心】
- hdu 5926/ Mr. Frog’s Game
- HDU 5926 Mr. Frog’s Game
- 2016CCPC东北地区大学生程序设计竞赛-Mr. Frog’s Game
- HDU 5926 Mr. Frog’s Game (水)
- hdu5926 Mr. Frog’s Game 小模拟 国庆咸鱼
- [2016CCPC东北地区大学生程序设计竞赛]Mr. Frog’s Game 遍历
- HDU Mr. Frog’s Game 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- Mr. Frog’s Game(弱校联盟十一专场(连连看))
- HDU 5926 Mr. Frog's Game 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- hdu 5926 Mr. Frog’s Game 2016CCPC东北地区大学生程序设计竞赛E题(模拟)
- (HDU 5926)Mr. Frog’s Game 水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- The Frog's Games
- hdu4004The Frog's Games
- IDEA创建AIDL示例
- uva 10129 Play on Words
- ARKit 获取识别到的水平面
- 关于iOS中的线程安全和使用场景
- wait()和notify()
- hdu5926Mr. Frog’s Game
- could-not-read-Username-for-https-github-com-Invalid-argument
- 三星910S3L安装系统修改Boot
- <job_demo><Qt>数据库简单查询
- 吴恩达教授的机器学习公开课
- python时间戳转换时间格式
- mybatis的缓存总结
- UEFI模式安装win10和Ubuntu 16.04 LTS双系统时遇到的问题
- 洛谷 P1980