(HDU 5926)Mr. Frog’s Game 水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
2017-01-03 19:40
501 查看
Mr. Frog’s Game
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
题意:
一个连连看的游戏,现在给你一个n*m的网格,你每次连接两个相同团的格点时只能水平或垂直的画3笔,问是否可以消掉一个。
分析:
由于格子是满的,且每次连接两个相同团的格点时只能水平或垂直的画3笔,所以当连接的是最外层的格点时,只要在同一行或同一列有相同的就可以消除。当连接内部的时,只能是消除两个相邻的相同的格点,判断和上下左右是否相同即可。
AC代码:
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
题意:
一个连连看的游戏,现在给你一个n*m的网格,你每次连接两个相同团的格点时只能水平或垂直的画3笔,问是否可以消掉一个。
分析:
由于格子是满的,且每次连接两个相同团的格点时只能水平或垂直的画3笔,所以当连接的是最外层的格点时,只要在同一行或同一列有相同的就可以消除。当连接内部的时,只能是消除两个相邻的相同的格点,判断和上下左右是否相同即可。
AC代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> using namespace std; const int maxn = 35; int n,m; int a[maxn][maxn]; int b[maxn]; bool judge1(int num) { for(int i=0;i<num;i++) { for(int j=i+1;j<num;j++) { if(b[i] == b[j]) return true; } } return false; } int main() { int t,kase = 1; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { scanf("%d",&a[i][j]); } } int f = false; // for(int i=0;i<m;i++) b[i] = a[0][i]; if(judge1(m)) { printf("Case #%d: Yes\n",kase++); continue; } // for(int i=0;i<m;i++) b[i] = a[n-1][i]; if(judge1(m)) { printf("Case #%d: Yes\n",kase++); continue; } // for(int i=0;i<n;i++) b[i] = a[i][0]; if(judge1(n)) { printf("Case #%d: Yes\n",kase++); continue; } // for(int i=0;i<n;i++) b[i] = a[i][m-1]; if(judge1(n)) { printf("Case #%d: Yes\n",kase++); continue; } // for(int i=1;i<n-1;i++) { if(f) break; for(int j=1;j<m-1;j++) { if(a[i][j] == a[i-1][j] || a[i][j] == a[i][j-1] || a[i][j] == a[i][j+1] || a[i][j] == a[i+1][j]) { f = true; break; } } } if(f) printf("Case #%d: Yes\n",kase++); else printf("Case #%d: No\n",kase++); } return 0; }
相关文章推荐
- (HDU 5924)Mr. Frog’s Problem 思维水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- HDU Mr. Frog’s Game 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- hdu 5926 Mr. Frog’s Game 2016CCPC东北地区大学生程序设计竞赛E题(模拟)
- HDU 5926 Mr. Frog's Game 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- (HDU 5927)Auxiliary Set 思维题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- (HDU 5929)Basic Data Structure 双端队列+模拟 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- HDU 5926 Mr. Frog’s Game(连连看,暴力)——2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- (HDU 5922)Minimum’s Revenge 思维水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- HDU Mr. Frog’s Problem 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- 【HDU5926 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 E】【水题】Mr. Frog’s Game 连连看
- HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- hdu 5924 Mr. Frog’s Problem(2016CCPC东北地区大学生程序设计竞赛 C题,数学思维)
- 【HDU5924 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 C】【水题】Mr. Frog’s Problem
- HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- HDU 5926 Mr. Frog's Game 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- hdu 5927 Auxiliary Set 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 F题(树状dp)
- [2016CCPC东北地区大学生程序设计竞赛]Mr. Frog’s Problem 规律+打表
- HDU 5924 Mr. Frog’s Problem(想看证明的来)——2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- HDU Basic Data Structure 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- 【HDU5929 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 H】【打表找规律 队列模拟】Basic Data Structure 双端栈下连续1和0做nand的结果