Five-In-a-Row CodeForces
来源:互联网 发布:漫画人软件 编辑:程序博客网 时间:2024/06/06 17:15
Five-In-a-Row CodeForces - 825B
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.
Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.
You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed that in the current arrangement nobody has still won.
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
XX.XX..........OOOO.................................................................................
YES
XXOXX.....OO.O......................................................................................
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char mp[12][12];int flag=0,sum=0;void dfs(int x,int y){ int i,j,t; for(i=x,j=y-1; j>=0; j--) //向左 { if(mp[i][j]!='X')break; else sum++; } for(i=x,j=y+1; j<10; j++) //向右 { if(mp[i][j]!='X')break; else sum++; } if(sum>=4) { flag=1; return ; } else sum=0; ////////////////////////////////////// for(i=x-1,j=y; i>=0; i--) //向上 { if(mp[i][j]!='X')break; else sum++; } for(i=x+1,j=y; i<10; i++) //向下 { if(mp[i][j]!='X')break; else sum++; } if(sum>=4) { flag=1; return ; } else sum=0; ////////////////////////////////////////// for(i=x,j=y,t=1;t<=4; t++) //向右上 { if(i-t<0||j+t>=10||mp[i-t][j+t]!='X') break; else sum++; } for(i=x,j=y,t=1;t<=4; t++) //向左下 { if(i+t<0||j-t>=10||mp[i+t][j-t]!='X') break; else sum++; } if(sum>=4) { flag=1; return ; } else sum=0; /////////////////////////////////////// for(i=x,j=y,t=1;t<=4; t++) //向右上 { if(i-t<0||j-t>=10||mp[i-t][j-t]!='X') break; else sum++; } for(i=x,j=y,t=1;t<=4; t++) //向右上 { if(i+t<0||j+t>=10||mp[i+t][j+t]!='X') break; else sum++; } if(sum>=4) { flag=1; return ; } else sum=0;}int main(){ while(gets(mp[0])) { for(int i=1; i<10; i++) scanf("%s",mp[i]); flag=0; sum=0; for(int i=0; i<10; i++) { for(int j=0; j<10; j++) { if(mp[i][j]=='.') { dfs(i,j); if(flag) break; } } if(flag) break; } if(flag) printf("YES\n"); else printf("NO\n"); getchar(); }}
NO
题意:10*10的棋盘内,如果加上一个‘X’后连续在水平,垂直,对角方向上出现5个以上的‘X’时输出YES,否则的话输出NO
思想及方法:向上向下,向左向右,向左上向右下,向左下向右上,分别找四个以上的话break;输出YES,找不到的话输出NO。
- Five-In-a-Row CodeForces
- Five-In-a-Row CodeForces
- Five-In-a-Row CodeForces
- Five-In-a-Row CodeForces
- Five-In-a-Row CodeForces
- Five-In-a-Row CodeForces
- Codeforces 825 B Five-In-a-Row
- CodeForces 825B Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- CodeForces 825B:Five-In-a-Row(模拟)
- B. Five-In-a-Row
- hdu 2291 Five in a Row, Again
- HDU 2699 Five in a Row (搜索)
- hdu2699 Five in a Row 暴力穷举
- B.Five-In-a-Row【逻辑+模拟】
- CodeForce 825B Five-In-a-Row
- 深度学习硬件平台
- DE1SOC OpenCL VGA 工程编译Mandelbrot
- POJ2299 [Ultra-QuickSort] 值域树状数组
- 和为S的数字及进阶
- C++进阶
- Five-In-a-Row CodeForces
- 第二章:Django模板的渲染
- CodeForces
- java 格式化输出(printf)
- 史上最全最强SpringMVC详细示例实战教程
- ONOS分布式数据结构弱一致性代码追踪
- 论文阅读-《Deformable Part-based Fully Convolutional Network for Object Detection》
- 数据(整型数、浮点数)在计算机内存中的存储方式
- 极光推送,如何接收推送下来的信息。