E - 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
题意 :
消消乐,消掉一个就yes,没有才no,但是只能消掉相邻的和同一条边上相同的数字(我玩的消消乐一直是这样的,好像你们城里人有不同的玩法)
思路:
我头脑比较简单,就直接存数了,然后遍历内部相邻且相同的元素。(代码较长)
#include<stdio.h>
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<math.h>
using namespace std ;
typedef long long ll;
#define maxn 10000005
#define INF 0x3f3f3f3f//将近int类型最大数的一半,而且乘2不会爆int
int main ()
{
int t;
cin >> t;
for(int l=0; l<t; ++l)
{
int a[35][35], b[35], c[35], d[35], e[35];
int n, m, flag = 1;
scanf("%d %d", &n, &m);
for(int i=0; i<n; ++i)
for(int j=0; j<m; ++j)
scanf("%d", &a[i][j]);
for(int i=0; i<m; ++i)//检验上边
b[i] = a[0][i];
sort(b, b+m);
for(int i=0; i<m-1; ++i)
if(b[i] == b[i+1])
{
flag = 0;
break;
}
for(int i=0; i<m; ++i)//检验下边
c[i] = a[n-1][i];
sort(c, c+m);
for(int i=0; i<m-1; ++i)
if(c[i] == c[i+1])
{
flag = 0;
break;
}
for(int i=0; i<n; ++i)//检验左边界
d[i] = a[i][0];
sort(d, d+n);
for(int i=0; i<n-1; ++i)
if(d[i] == d[i+1])
{
flag = 0;
break;
}
for(int i=0; i<n; ++i)//检验右边界
e[i] = a[i][m-1];
sort(e, e+n);
for(int i=0; i<n-1; ++i)
if(e[i] == e[i+1])
{
flag = 0;
break;
}
for(int i=1; i<n-1; ++i)//遍历内部相邻且相同元素
for(int j=1; j<m-1; ++j)
if(a[i][j] == a[i-1][j] || a[i][j] == a[i+1][j] || a[i][j] == a[i][j-1] || a[i][j] == a[i][j+1])
{
flag = 0;
break;
}
if(flag)
printf("Case #%d: No\n", l+1);
else
printf("Case #%d: Yes\n", l+1);
}
return 0;
}
ps:消消乐还有啥玩法呢?请在下方留言。。。。。。