校第十六届大学生程序设计竞赛暨2016省赛集训队选拔赛1007
来源:互联网 发布:4gip网络加速器.apk 编辑:程序博客网 时间:2024/05/22 06:28
Problem G
Problem Description
Gomoku is an abstract strategy board game. Named Gobang or Five in a Row as well, it is traditionally played with pieces of two colors (black and white) on a board (with N×M intersections). Once a piece is placed, it is not allowed to be moved or removed from the chessboard.
The rules of the game are quite simple. The black plays first, and two players alternate in placing a stone of their own color on an empty intersection. The winner is the first one who gets an unbroken row of five stones of his/her color horizontally, vertically, or diagonally.
Now we have already drawn some stages of the game, and you're required to answer, that for each stage whether it is possible to reach, and if so, who has already won the game. You have to solve it as soon as possible, because there are no much time left in the competition now!
The rules of the game are quite simple. The black plays first, and two players alternate in placing a stone of their own color on an empty intersection. The winner is the first one who gets an unbroken row of five stones of his/her color horizontally, vertically, or diagonally.
Now we have already drawn some stages of the game, and you're required to answer, that for each stage whether it is possible to reach, and if so, who has already won the game. You have to solve it as soon as possible, because there are no much time left in the competition now!
Input
The number of test cases T(T≤150) will occur in the first line of input.
For each test case:
The first line contains the size of the board N and M(1≤N,M≤100).
Then N lines followed, each with exactly M characters. The white stone is denoted by '1', and the black stone is denoted by '2', while the empty intersections are denoted by '.' (a full period).
For each test case:
The first line contains the size of the board N and M(1≤N,M≤100).
Then N lines followed, each with exactly M characters. The white stone is denoted by '1', and the black stone is denoted by '2', while the empty intersections are denoted by '.' (a full period).
Output
For each test case, if it is impossible to arrive at such a stage, output “fault”. Otherwise, if the white piece wins, then output “white”; if the black piece wins, output “black”; or else output “other”.
Sample Input
210 10.......................1.........2..................................................................10 10.................................1........1.........1.2.............................................
Sample Output
otherfault#include<cstdio>using namespace std;const int N=110;int vis[N][N];char s[N][N];int n,m;int getnum(char p){ int i,j,t=0; for(i=1;i<=n;i++)for(j=1;j<=m;j++) vis[i][j]=0; for(i=1;i<=n-4;i++) { for(j=1;j<=m-4;j++) { if(s[i][j]==p&&s[i+1][j+1]==p&&s[i+2][j+2]==p&&s[i+3][j+3]==p&&s[i+4][j+4]==p) { t++; vis[i][j]++;vis[i+1][j+1]++;vis[i+2][j+2]++;vis[i+3][j+3]++;vis[i+4][j+4]++; } } } for(i=1;i<=n-4;i++) { for(j=m;j>=5;j--) { if(s[i][j]==p&&s[i+1][j-1]==p&&s[i+2][j-2]==p&&s[i+3][j-3]==p&&s[i+4][j-4]==p) { t++; vis[i][j]++;vis[i+1][j-1]++;vis[i+2][j-2]++;vis[i+3][j-3]++;vis[i+4][j-4]++; } } } for(i=1;i<=n;i++) { for(j=1;j<=m-4;j++) { if(s[i][j]==p&&s[i][j+1]==p&&s[i][j+2]==p&&s[i][j+3]==p&&s[i][j+4]==p) { t++; vis[i][j]++;vis[i][j+1]++;vis[i][j+2]++;vis[i][j+3]++;vis[i][j+4]++; } } } for(i=1;i<=n-4;i++) { for(j=1;j<=m;j++) { if(s[i][j]==p&&s[i+1][j]==p&&s[i+2][j]==p&&s[i+3][j]==p&&s[i+4][j]==p) { t++; vis[i][j]++;vis[i+1][j]++;vis[i+2][j]++;vis[i+3][j]++;vis[i+4][j]++; } } } return t;}int check(char p){ int t=getnum(p),i,j; for(i=1;i<=n;i++) for(j=1;j<=m;j++) if(vis[i][j]==t)return 1; return 0;}int main(){ int T,i,j,cnt1,cnt2,cnt3,cnt4; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(i=1;i<=n;i++) { scanf("%s",s[i]+1); } cnt1=0;cnt2=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(s[i][j]=='1') cnt1++; else if(s[i][j]=='2') cnt2++; } } if(cnt1!=cnt2&&cnt1!=cnt2-1) { printf("fault\n"); continue; } cnt3=getnum('1');cnt4=getnum('2'); if(!cnt3&&!cnt4) { printf("other\n"); continue; } if(cnt3&&cnt4) { printf("fault\n"); continue; } if(cnt3&&cnt1!=cnt2) { printf("fault\n"); continue; } if(cnt4&&cnt1!=cnt2-1) { printf("fault\n"); continue; } if(cnt3) { if(check('1')) printf("white\n");else printf("fault\n"); } else { if(check('2')) printf("black\n");else printf("fault\n"); } } return 0;}
0 0
- 校第十六届大学生程序设计竞赛暨2016省赛集训队选拔赛1007
- 校第十六届大学生程序设计竞赛暨2016省赛集训队选拔赛1002
- 校第十六届大学生程序设计竞赛暨2016省赛集训队选拔赛(Problem E)
- 杭电校第十七届程序设计竞赛暨2017省赛集训队选拔赛
- NYIST—2017年第十届河南省大学生程序设计竞赛选拔赛—个人赛总结
- “华为杯”苏、鲁高校大学生程序设计大赛选拔赛暨东南大学第十届程序设计竞赛复赛总结
- 2013ACM/ICPC湘潭多省程序设计竞赛暨湘潭市第五届大学生程序设计竞赛
- 第八届福建省大学生程序设计竞赛 省赛回忆
- 2016中国大学生程序设计竞赛 - 网络选拔赛 1007 Mountain hdu5838
- 2016 第七届福建省大学生程序设计竞赛
- 2016中国大学生程序设计竞赛 - 网络选拔赛
- 2016中国大学生程序设计竞赛 - 网络选拔赛
- 2016中国大学生程序设计竞赛网络选拔赛
- 2016中国大学生程序设计竞赛 - 网络选拔赛 1001
- 2016中国大学生程序设计竞赛 - 网络选拔赛 1011
- 2016中国大学生程序设计竞赛 - 网络选拔赛
- 2014年第四届“华为杯”南邮大学生程序设计竞赛之选拔赛 D演唱顺序问题
- 2013“嘉杰信息”杯ACM/ICPC湘潭多省程序设计竞赛暨湘潭市第五届大学生程序设计竞赛
- vijos1025小飞侠的游园方案
- 第十三讲--PGA内存作用和构成
- java学习笔记9--内部类总结
- ThinkPHP 自动完成 和 自动验证
- google2016面试题-count of smaller numbers after self
- 校第十六届大学生程序设计竞赛暨2016省赛集训队选拔赛1007
- python系列之 RabbitMQ -- TOPICS
- python解析xml示例
- OCP试题
- 树莓派3配置局域网打印服务器惠普打印机HP1108
- 递归调用(实现汉诺塔)
- apt-get update 过期
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A B C
- 第十四讲--PGA管理和调整