`
xxx0624
  • 浏览: 32117 次
文章分类
社区版块
存档分类
最新评论

HDU2699+Easy

 
阅读更多

简单题。

/*

*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<math.h>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define MP(a,b) make_pair((a),(b)) 
const int maxn = 18;
const int inf = 0x7fffffff;
const double pi=acos(-1.0);
const double eps = 1e-8;
char mat[ maxn ][ maxn ];
bool flag;
const int dx[]={1,-1,0,0,-1,-1,1,1};
const int dy[]={0,0,1,-1,-1,1,-1,1};

bool in( int x,int y ){
	if( x>=0&&x<15&&y>=0&&y<15 )
		return true;
	else
		return false;
}

bool Judge( int x,int y,char xx ){
	for( int i=0;i<8;i++ ){
		int tx = x+dx[i];
		int ty = y+dy[i];
		if( in(tx,ty)==true&&mat[tx][ty]==xx )
			return true;
	}
	return false;
}

int bfs( int x,int y,char xx ){
	
	int tx = x+1;
	int ty = y;
	int cnt = 0;
	while( tx<15 ){
		if( mat[tx][ty]==xx ){
			cnt++;
			tx++;
			if( cnt>=4 ) break;
		}
		else 
			break;
	}
	tx = x-1;
	while( tx>=0 ){
		if( mat[tx][ty]==xx ){
			cnt++;
			tx--;
			if( cnt>=4 ) break;
		}
		else 
			break;
	}
	if( cnt>=4 ) return 5;
	//row to "5"
	tx = x;
	ty = y+1;
	cnt = 0;
	while( ty<15 ){
		if( mat[tx][ty]==xx ){
			cnt++;
			ty++;
			if( cnt>=4 ) break;
		}
		else 
			break;
	}
	ty = y-1;
	while( ty>=0 ){
		if( mat[tx][ty]==xx ){
			cnt++;
			ty--;
			if( cnt>=4 ) break;
		}
		else 
			break;
	}
	if( cnt>=4 ) return 5;
	// col to "5"
	tx = x+1;
	ty = y+1;
	cnt = 0;
	while( tx<15&&ty<15 ){
		if( mat[tx][ty]==xx ){
			cnt++;
			tx++;
			ty++;
			if( cnt>=4 ) break;
		}
		else 
			break;
	}
	tx = x-1;
	ty = y-1;
	while( tx>=0&&ty>=0 ){
		if( mat[tx][ty]==xx ){
			cnt++;
			tx--;
			ty--;
			if( cnt>=4 ) break;
		}
		else 
			break;
	}
	if( cnt>=4 ) return 5;
	//right up to "5"
	tx = x-1;
	ty = y+1;
	cnt = 0;
	while( tx>=0&&ty<15 ){
		if( mat[tx][ty]==xx ){
			cnt++;
			tx--;
			ty++;
			if( cnt>=4 ) break;
		}
		else 
			break;
	}
	tx = x+1;
	ty = y-1;
	while( tx<15&&ty>=0 ){
		if( mat[tx][ty]==xx ){
			cnt++;
			tx++;
			ty--;
			if( cnt>=4 ) break;
		}
		else 
			break;
	}
	if( cnt>=4 ) return 5;
	//left up to "5"
	return -1;
}

int main(){
	int T;
	scanf("%d",&T);
	while( T-- ){
		int cnt1 = 0;
		int cnt2 = 0;
		for( int i=0;i<15;i++ ){
			scanf("%s",mat[i]);
			for( int j=0;j<15;j++ ){
				if( mat[i][j]=='W' ) cnt1++;
				if( mat[i][j]=='B' ) cnt2++;
			}
		}
		char xx ;
		if( cnt1==cnt2 ) xx = 'B';
		else xx = 'W';
		flag = false;
		for( int i=0;i<15;i++ ){
			for( int j=0;j<15;j++ ){
				if( mat[i][j]=='.'&&Judge( i,j,xx )==true ){//i,j周围有 xx
					if( bfs( i,j,xx )>=5 ){
						flag = true;
						break;
					}
				}
			}
			if( flag==true ) break;
		}
		if( flag ) puts("YES");
		else puts("NO");
	}
	return 0;
}



分享到:
评论

相关推荐

    HDU ACM as easy as a+b

    - **as easy as a+b** 这个短语在这类题目中通常用来暗示题目难度较低,意味着只需要简单的数学加法操作即可完成任务。 #### 标签:ACM - 标签“ACM”再次强调了本题与ACM程序设计竞赛的相关性,提示读者此题可能...

    HDU2501解题报告

    题目“HDU2501 Tiling_easy version”是一个经典的动态规划问题,涉及到二维空间的骨牌覆盖。在这个问题中,我们需要在一个2行n列的网格上使用两种不同规格的骨牌来完全覆盖网格,骨牌的规格为2x1和2x2。目标是找出...

    ACM课件!!(lecture_07)计算几何基础_easy

    ACM课件!!(lecture_07)计算几何基础_easy ACM课件!!(lecture_07)计算几何基础_easy hdu acm usa 测试数据 算法

    leetcode答案-ACM-Problem:C++算法

    45B,这题读懂题意就很easy,可惜我看题看了俩个多小时还是没有明白,最后基友给讲解的题意(我的六级证是假的2333. ..) 看懂题意, 理解公式的意思, 注意题目中出现的变量以及他们在题中所给的公

Global site tag (gtag.js) - Google Analytics