简单题。
/*
*/
#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;
}
分享到:
相关推荐
300+ AC 代码 。 大数 , 线段树 , 字符串 , dp.....
2、new做两件事,一是分配内存,二是调用类的构造函数 3、new建立的是一个对象,而malloc分配的是一块内存 4、new/delete是保留字,不需要头文
acm hdu as easy as a+b
本人准备2020年保研机试时刷的题目(虽然最后机试取消了,...来自某中流985,在HDU和vjudge平台上大概刷了400道。本文件地图(excel表格)包含了绝大部分我刷过的题目,笔记中具有思路、代码、总结和心得。 大佬勿入!
ACM题库,一些题目和答案,以及解题报告,传上来共享
杭电OnlineJudge 200-2099的解题报告
acm入门训练和日常训练 对于初学者以及acm爱好者有叫大帮助
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
hdu 1695 GCD(欧拉函数+容斥原理).docx
HDU1059的代码
杭电ACMhdu1163
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
HDU2501 Tiling_easy version 解题报告
Problem Description 话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”。 这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加法。...
搜索 dfs 解题代码 hdu1241
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。