热身二 E - Mr. Frog’s Game HDU - 5926

原题

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

解题思路

模拟实现连连看的思路就可以了,符合题意有两种情况(1)在内部有相邻且相同两个方格(2)两个标号相同的边同时出现在第一行或者第n行,第一列或者第m列,实现这个过程就好了

反思

可以函数封装的部分没有封装导致,代码很乱,
没有看清输出导致WA了一发

AC代码

#include<iostream>
#include<cstring>
using namespace std;
int a[35][35];
int n,m,t,flag;
int cnt;
int vis[905];
int main(){
	cin>>t;
	while(t--){
		cin>>n>>m;
		memset(a,0,sizeof a);
		memset(vis ,0,sizeof vis);
		flag=0;
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
			
			if(a[i][j]==a[i][j+1]||a[i][j]==a[i][j-1]||a[i][j]==a[i-1][j]||a[i][j]==a[i+1][j]) {
				flag=1;
				break;
			}
		}
		if(flag==1) break;
		}
		if(flag==1) {
			cout<<"Case #"<<++cnt<<": Yes\n";
			continue;
		}
		memset(vis,0,sizeof vis);
		for(int i=1;i<=m;i++){
			if(vis[a[1][i]]==0) vis[a[1][i]]=1;
			else {
				flag=1;
				break;
			}
		}
		if(flag==1) {
			cout<<"Case #"<<++cnt<<": Yes\n";
			continue;
		}
		memset(vis,0,sizeof vis);
		for(int i=1;i<=m;i++){
			if(vis[a[n][i]]==0) vis[a[n][i]]=1;
			else {
				flag=1;
				break;
			}
		}
		if(flag==1) {
			cout<<"Case #"<<++cnt<<": Yes\n";
			continue;
		}
		memset(vis,0,sizeof vis);
		for(int i=1;i<=n;i++){
			if(vis[a[i][1]]==0) vis[a[i][1]]=1;
			else {
				flag=1;
				break;
			}
		}
		if(flag==1) {
			cout<<"Case #"<<++cnt<<": Yes\n";
			continue;
		}
		memset(vis,0,sizeof vis);
		for(int i=1;i<=n;i++){
			if(vis[a[i][m]]==0) vis[a[i][m]]=1;
			else {
				flag=1;
				break;
			}
		}
		if(flag==1) {
			cout<<"Case #"<<++cnt<<": Yes\n";
			continue;
		}
		cout<<"Case #"<<++cnt<<": No\n";
	}
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值