博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU2699+Easy
阅读量:4563 次
发布时间:2019-06-08

本文共 2475 字,大约阅读时间需要 8 分钟。

简单题。

 

/**/#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long int64;//typedef __int64 int64;typedef pair
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;}

 

转载于:https://www.cnblogs.com/pangblog/p/3257944.html

你可能感兴趣的文章
Java封装servlet发送请求(二)
查看>>
python基础复习汇总
查看>>
go pkg
查看>>
解剖 CPU
查看>>
404 Note Found 队-课堂实战-项目UML设计
查看>>
HTTP协议(收藏)
查看>>
(原创)如何获取网页URL的source code (Android)
查看>>
JavaScript之函数作用域
查看>>
仿迅雷播放器教程 -- C++界面制作方法的对比 (9)
查看>>
近期计划
查看>>
解决DFS Locations从Eclipse的Navigator中消失的问题
查看>>
Vue搭建项目
查看>>
java学习笔记《一》网络编程基础
查看>>
设计模式
查看>>
mysqld_safe A mysqld process already exists
查看>>
六年测试之精华分享:产品质量应从哪些方面提高
查看>>
文件处理
查看>>
for循环
查看>>
【转】Android手机客户端关于二维码扫描的源码--不错
查看>>
【转】Java 多线程(四) 多线程访问成员变量与局部变量
查看>>