Five-In-a-Row CodeForces
来源:互联网 发布:godaddy 域名优惠码 编辑:程序博客网 时间:2024/06/15 16:43
大致题意:题意很简单,就是两个人在下五子棋,一个人的棋子是X,另一个人的棋子是O,现在轮到X了,问能否在“ . ”区域放一个棋子使得在八个方向上的任意一个方向上能构成五个或者五个以上的连续X棋子,如果可以输出YES,否则输出NO
大致思路:一开始想的用dfs,但是想的太复杂了,没有做出来,最后看了队友的思想,直接暴力八个方向,因为棋盘区域才是10X10的,完全没问题,代码也很简单
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>#include<string.h>#include<algorithm>using namespace std;char map[12][12];int n;void dfs(int x,int y){ int xx,yy,sum,i,j; xx=x; yy=y; sum=0; //下面是扩展八个方向,有一个方向满足连续五个棋子就可以输入YES for(i=xx; i>=0; i--) { if(map[i][yy]!='X') break; else sum++; } for(i=xx+1; i<10; i++) { if(map[i][yy]!='X') break; else sum++; } if(sum>=5)n=1; sum=0; for(i=yy; i>=0; i--) { if(map[xx][i]!='X') break; else sum++; } for(i=yy+1; i<10; i++) { if(map[xx][i]!='X') break; else sum++; } if(sum>=5)n=1; sum=0; for(i=xx,j=yy; i>=0&&j>=0; i--,j--) { if(map[i][j]!='X') break; else sum++; } for(i=xx+1,j=yy+1; i<10&&j<10; i++,j++) { if(map[i][j]!='X') break; else sum++; } if(sum>=5)n=1; sum=0; for(i=xx,j=yy; i>=0&&j<10; i--,j++) { if(map[i][j]!='X') break; else sum++; } for(i=xx+1,j=yy-1; i<10&&j>=0; i++,j--) { if(map[i][j]!='X') break; else sum++; } if(sum>=5)n=1;}int main(){ int i,j; for(i=0; i<10; i++) scanf("%s",map[i]); n=0; for(i=0; i<10; i++) for(j=0; j<10; j++) { if(map[i][j]=='.') { map[i][j]='X'; //标记 dfs(i,j); map[i][j]='.'; //深搜回溯 } } if(n==1)printf("YES\n"); else printf("NO\n"); return 0;}
- 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
- Hadoop FileSystem
- 周志华《Machine Learning》学习笔记(17)--强化学习
- jsp笔记二
- js面向对象编程(1)--构造函数与new命令
- 数据结构(第二天)单链表的基本操作,创建单链表,头插法,尾插法,删除节点,查询节点
- Five-In-a-Row CodeForces
- .gitignore文件
- 检查和消除内存泄露
- 【spingmvc基础】springmvc的拦截器
- NAT技术和代理服务器
- IO流文件复制缓冲效率测试
- Prime Ring Problem(经典回溯法)
- KMP-hdu1711
- Game of Connections(卡特兰数)