Five-In-a-Row CodeForces
来源:互联网 发布:商务部零售数据 编辑:程序博客网 时间:2024/06/05 03:41
Five-In-a-Row
CodeForces - 82Alice 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 10characters 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
题意:下五子棋,再下一个‘X’能赢输出‘YES’,否则输出‘NO’。
题解:这题可以用普通方法做,如下;从'.'处开始调用,找他的方向,分为四组,也就是横竖和两个斜线(五子棋赢的方式),调用里的方向分别为左右,上下,左上右下,右上左下两两一组;只要有一组有四个或四个以上就输出‘YES’,四组都没有就标记一下输出‘NO’。
代码:
#include<stdio.h>#include<string.h>int sum,flag;char mp[15][15];void pre(int x,int y){ int i,j; 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; printf("YES\n"); return ; } else sum=0; for(i=x+1,j=y;i<10;i++)//向下 { if(mp[i][j]!='X') break; else sum++; } for(i=x-1,j=y;i>=0;i--)//向上 { if(mp[i][j]!='X') break; else sum++; } if(sum>=4) { flag=1; printf("YES\n"); return ; } else sum=0; for(j=y,i=x-1;i>=0;i--)//上左 { j--; if(j<0) break; if(mp[i][j]!='X') break; else sum++; } for(j=y,i=x+1;i<10;i++)//下右 { j++; if(j>=10) break; if(mp[i][j]!='X') break; else sum++; } if(sum>=4) { flag=1; printf("YES\n"); return ; } else sum=0; for(j=y,i=x-1;i>=0;i--)//上右 { j++; if(j>=10) break; if(mp[i][j]!='X') break; else sum++; } for(j=y,i=x+1;i<10;i++)//下左 { j--; if(j<0) break; if(mp[i][j]!='X') break; else sum++; } if(sum>=4) { flag=1; printf("YES\n"); return ; } else sum=0;}int main(){ while(~scanf("%s",mp[0])) { int i,j; flag=0; for(i=1;i<10;i++) scanf("%s",mp[i]); for(i=0;i<10;i++) { for(j=0;j<10;j++) { if(mp[i][j]=='.') { sum=0; pre(i,j); if(flag==1) break; } } if(flag==1) break; } if(flag==0) printf("NO\n"); }}
- 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
- HBase的put流程源码分析
- printf()函数
- 自定义EL函数的步骤
- Java程序基础面试题(一)
- 7/14 CCF YOCSEF学术报告会:区块链技术
- Five-In-a-Row CodeForces
- jsonp原理,应用场景,优缺点
- 【SVN】总结
- Leetcode67. Add Binary
- Android源码解析四大组件系列(五)---广播的注册过程
- pandas处理字符串1
- CodeForces
- Five-In-a-Row CodeForces
- SpringBoot结合MongoDB简单应用