CodeForces
来源:互联网 发布:安非他命如是我闻 知乎 编辑:程序博客网 时间:2024/06/05 05:35
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.
Input
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.
Output
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
Example
Input
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........
Output
YES
Input
XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........
Output
NO
题意:五子棋,找出横排或者竖排或者对角线能组成五个'X'则输出“YES”,否则输出“NO”。
用暴力,找出一个' . ' 点,从它的横排。竖排,和对角线开始搜,如果和它相邻的'X'数量>=4,就能组成五子棋,用f标记已经找到,break。
若f=1,输出“YES”,否则输出“NO”。
#include<stdio.h>#include<string.h>int main(){ char str[20][20]; int f; while(~scanf("%s",str[0])) { for(int i=1; i<10; i++) scanf("%s",str[i]); f=0; int sum; for(int i=0; i<10; i++) { if(f) break; for(int j=0; j<10; j++) { if(str[i][j]=='.') { sum=0; for(int k=i+1; k<10; k++)//竖排向下搜 if(str[k][j]=='X') sum++; else break; for(int k=i-1; k>=0; k--)//竖排向上搜 if(str[k][j]=='X') sum++; else break; if(sum>=4) { f=1; break; } sum=0; for(int k=j+1; k<10; k++) 横排向右搜 if(str[i][k]=='X') sum++; else break; for(int k=j-1; k>=0; k--)横排向左搜 if(str[i][k]=='X') sum++; else break; if(sum>=4) { f=1; break; } sum=0; for(int k=i+1,r=j+1; k<10&& r<10; k++,r++)右下 if(str[k][r]=='X') sum++; else break; for(int k=i-1,r=j-1; k>=0&&r>=0; k--,r--)左上 if(str[k][r]=='X') sum++; else break; if(sum>=4) { f=1; break; } sum=0; for(int k=i+1,r=j-1; k<10&&r>=0; k++,r--)//左下 if(str[k][r]=='X') sum++; else break; for(int k=i-1,r=j+1; k>=0&&r<10; k--,r++)//右上 if(str[k][r]=='X') sum++; else break; if(sum>=4) { f=1; break; } } } } if(f) printf("YES\n"); else printf("NO\n"); } return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- freemarker前台接收后台传递过来的map数据处理问题
- js判断是否是当前点击对象
- linux基础一
- Spring Boot 集成Shiro和CAS
- Python3 异常处理
- CodeForces
- java中的正则表达式
- Guava
- jconsole 和jvisualVM 监控远程 spring boot程序
- mybatis系列4-多表查询
- Windows Manifest文件简介
- C语言中变量的生命周期和作用域
- obiee 导出excel,pdf报错
- 牛顿迭代法 简单入门