CodeForces
来源:互联网 发布:淘宝优化怎么做 编辑:程序博客网 时间:2024/06/06 00:32
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......................................................................................
NO
思路:把‘ . ’一个个枚举出来,然后判断它的上方,下方;左方,右方;左上方,右下方;右上方,左下方;能否五个
连成一线。
代码:
#include<stdio.h>char map[15][15];int main(){ int i,j,k,q; for(i=0; i<10; i++) scanf("%s",map[i]); for(i=0; i<10; i++) { for(j=0; j<10; j++) { if(map[i][j]=='.') { int s=1;//初始化为1; for(int k=j+1; k<10; k++)//右方向 { if(map[i][k]=='X') { s++; if(s==5)//连接5个棋子 { printf("YES\n"); return 0; } } else break; } for(int k=j-1; k>=0; k--) //左方向 { if(map[i][k]=='X') { s++; if(s==5)//连接5个棋子 { printf("YES\n"); return 0; } } else break; } s=1; for(int k=i+1; k<10; k++) //上方 { if(map[k][j]=='X') { s++; if(s==5) { printf("YES\n"); return 0; } } else break; } for(int k=i-1; k>=0; k--) //下方 { if(map[k][j]=='X') { s++; if(s==5)//连接5个棋子 { printf("YES\n"); return 0; } } else break; } s=1; for(k=i-1,q=j-1; q>=0,k>=0; q--,k--) //左上方 { if(map[k][q]=='X') { s++; if(s==5)//连接5个棋子 { printf("YES\n"); return 0; } } else break; } for(k=i+1,q=j+1; q<10,k<10; q++,k++)//右下方 { if(map[k][q]=='X') { s++; if(s==5)//连接5个棋子 { printf("YES\n"); return 0; } } else break; } s=1; for(k=i+1,q=j-1; q>=0,k<10; q--,k++)// 右上方 { if(map[k][q]=='X') { s++; if(s==5)//连接5个棋子 { printf("YES\n"); return 0; } } else break; } for(k=i-1,q=j+1; q<10,k>=0; q++,k--)//左下方 { if(map[k][q]=='X') { s++; if(s==5)//连接5个棋子 { printf("YES\n"); return 0; } } else break; } }}} printf("NO\n"); return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 浅谈进程地址空间与虚拟存储空间
- antiSMASH数据库:微生物次生代谢物合成基因组簇查询和预测
- 最大差值
- HDU 1257 最少导弹拦截系统(DP)
- oracle 客户端数据库安装图文操作步骤
- CodeForces
- 面向对象 中继承的特点
- 保证分布式系统数据一致性的6种方案
- Android Zip4J 使用笔记
- 关于字符串长度、字符串逆序的相关程序
- C++学习笔记之SOCKET编程
- 直方图均衡化算法原理与实现
- Linux学习笔记
- 深入JVM内存区域