【HDU5926 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 E】【水题】Mr. Frog’s Game 连连看
来源:互联网 发布:c语言编写100以内素数 编辑:程序博客网 时间:2024/04/29 12:05
Mr. Frog’s Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 133 Accepted Submission(s): 103
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<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }#define MS(x,y) memset(x,y,sizeof(x))#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }const int N = 0, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }int casenum, casei;int n, m;int a[32][32];set<int>sot;bool check(){for (int i = 1; i <= n; ++i){for (int j = 1; j <= m; ++j){if (j < m && a[i][j] == a[i][j + 1]|| i < n && a[i][j] == a[i + 1][j])return 1;}}sot.clear();for (int i = 1; i <= n; ++i){if (sot.count(a[i][1]))return 1;sot.insert(a[i][1]);}sot.clear();for (int i = 1; i <= n; ++i){if (sot.count(a[i][m]))return 1;sot.insert(a[i][m]);}sot.clear();for (int i = 1; i <= m; ++i){if (sot.count(a[1][i]))return 1;sot.insert(a[1][i]);}sot.clear();for (int i = 1; i <= m; ++i){if (sot.count(a[n][i]))return 1;sot.insert(a[n][i]);}return 0;}int main(){scanf("%d", &casenum);for (casei = 1; casei <= casenum; ++casei){scanf("%d%d", &n, &m);for (int i = 1; i <= n; ++i){for (int j = 1; j <= m; ++j){scanf("%d", &a[i][j]);}}printf("Case #%d: %s\n", casei, check() ? "Yes" : "No");}return 0;}/*【trick&&吐槽】好好读题看数据*/
0 0
- 【HDU5926 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 E】【水题】Mr. Frog’s Game 连连看
- HDU 5926 Mr. Frog’s Game(连连看,暴力)——2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- (HDU 5926)Mr. Frog’s Game 水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- HDU Mr. Frog’s Game 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- 【HDU5924 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 C】【水题】Mr. Frog’s Problem
- 2016CCPC东北地区大学生程序设计竞赛-Mr. Frog’s Game
- hdu 5926 Mr. Frog’s Game 2016CCPC东北地区大学生程序设计竞赛E题(模拟)
- HDU Mr. Frog’s Problem 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- 2016CCPC东北地区大学生程序设计竞赛-Mr. Frog’s Problem
- (HDU 5924)Mr. Frog’s Problem 思维水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- HDU 5924 Mr. Frog’s Problem(想看证明的来)——2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- [2016CCPC东北地区大学生程序设计竞赛]Mr. Frog’s Game 遍历
- HDU 5926 Mr. Frog's Game 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- [2016CCPC东北地区大学生程序设计竞赛]Mr. Frog’s Problem 规律+打表
- HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- 【HDU5922 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 A】【水题】Minimum’s Revenge
- 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 部分题解
- hdu 5924 Mr. Frog’s Problem(2016CCPC东北地区大学生程序设计竞赛 C题,数学思维)
- 简单几步让你的 Mac 系统恢复如新
- 类关系
- Android性能优化之常见的内存泄漏
- Make & Makefile
- Three.js讲解以及WEBGL实例
- 【HDU5926 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 E】【水题】Mr. Frog’s Game 连连看
- 为什么说B+树比B 树更适合实际应用中操作系统的文件索引和数据库索引?
- Android RecyclerView(瀑布流)水平/垂直方向分割线
- Unit Testing With Android Studio
- hdu5914 Triangle(思路)
- 不同语言使用HMAC SHA256创建base64哈希加密
- 使用 BootstrapTable 实现数据的分页显示(一)
- Three.js展示模型问题总结
- SDUTACM 顺序表应用8:最大子段和之动态规划法