hdu2699
来源:互联网 发布:中国移动 plmn 网络id 编辑:程序博客网 时间:2024/06/12 22:57
Five in a Row
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 364 Accepted Submission(s): 159
Problem Description
The ACM Team of WHU is planning an online AI arena for Go-bang (Five in a Row). Now, we need some help.
We all know the famous game "Five in a Row". It is traditionally played with go pieces (black and white stones) on a go
board (15x15 intersections). The winner is the first player to get an unbroken row of five stones horizontally, vertically, or
diagonally.
We now have an uncompleted game, that is to say, yet no one won. You are required to tell us that whether the next player
could win within one step or not.
We all know the famous game "Five in a Row". It is traditionally played with go pieces (black and white stones) on a go
board (15x15 intersections). The winner is the first player to get an unbroken row of five stones horizontally, vertically, or
diagonally.
We now have an uncompleted game, that is to say, yet no one won. You are required to tell us that whether the next player
could win within one step or not.
Input
The input consists of multiple test cases. The first line of input contains an integer T, which is the number of test cases.
Each test case is a 15 * 15 go board, 'B' represent for a black stone while 'W' for white ones. '.' represents cross with no
stone represented by 0.
[Technical Specification]
T is an integer, and T <= 20.
The number of white stones is either equal or 1 less than the number of black stones.
There is at least ONE '.' in each test case.
Test cases are separated by ONE empty line.
You can assume that black player goes first.
Each test case is a 15 * 15 go board, 'B' represent for a black stone while 'W' for white ones. '.' represents cross with no
stone represented by 0.
[Technical Specification]
T is an integer, and T <= 20.
The number of white stones is either equal or 1 less than the number of black stones.
There is at least ONE '.' in each test case.
Test cases are separated by ONE empty line.
You can assume that black player goes first.
Output
For each test case, print a single line containing the result. If the next player could win within one step, display 'YES',
otherwise, display 'NO'.
otherwise, display 'NO'.
Sample Input
2 ........W...... ..W......W...B. .W....B........ .W.......W..... ..BB....W...... ...B........... ....B........WW ...........B... ....W.......... .W..B.B....WBB. BW........B.W.B ............... W.....BB.W....W B..B.W.BB....B. ........WW..... ...B...W..BBW.. W..WBW..W...B.. ...W..WBW...... .....BWW..B.B.. ..BW.B.B..W.... B..W..WBW...... B......B......W B.B...B....W... ....B.WB...B... B.W............ .....WW...B.... ..B.....B...W.W .W.........WBW. B.............. ..W.B...W..W..B
Sample Output
NOYESAC代码:#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> using namespace std; const int N = 15; char map[N+9][N+9]; int dx[]={0,0,-1,1,-1,1,-1,1}; int dy[]={-1,1,0,0,-1,1,1,-1}; bool ok(int x,int y) { if(x<0||x>=N) return false; if(y<0||y>=N) return false; return true; } int s(int x,int y,char K,int dir) { int ans = 0; while(1) { x=x+dx[dir],y=y+dy[dir]; if(!ok(x,y)) return ans; if(map[x][y]==K) ans++; else return ans; } } bool oor(int x,int y,char K) { for(int i=0;i<4;i++) { if(s(x,y,K,i*2)+s(x,y,K,i*2+1)>=4) return true; } return false; } void solve(char K) { for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(map[i][j]=='.') { if(oor(i,j,K)) { printf("YES\n"); return ; } } printf("NO\n");return ; } int main() { int cas; scanf("%d",&cas); while(cas--) { int w=0,b=0; for(int i=0;i<N;i++) { scanf("%s",map[i]); for(int j=0;j<N;j++) if(map[i][j]=='B') b++; else if(map[i][j]=='W') w++; } if(b==w) solve('B'); else solve('W'); } return 0; }
阅读全文
0 0
- hdu2699
- HDU2699+Easy
- Romatic HDU2699
- HDU2699 扩展欧几里德
- Romantic(hdu2699+欧几里德)
- hdu2699 Five in a Row 暴力穷举
- JavaEE目录
- (int&)a和(int)a的区别
- 英语魔法师之语法俱乐部阅读笔记
- 23种设计模式学习系列---概括
- caffe可视化方法(21天实战caffe)python版
- hdu2699
- linux学习笔记之shell介绍及其他命令
- Gitlab 服务器url修改后,项目path的修改
- ES6 Proxy
- java集合框架之TreeSet类
- Bootstrap学习笔记(三)
- Ubuntu配置Shadowsocks qt5
- 动态规划------走楼梯问题
- c++中内存拷贝函数(C++ memcpy)详解