Codeforces Round #390(Div. 2)B. Ilya and tic-tac-toe game【模拟】
来源:互联网 发布:外文数据库 免费搜索 编辑:程序博客网 时间:2024/05/16 06:19
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first getsthree of his signs in a row next to each other (horizontal, vertical or diagonal).
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letterx), or 'o' (lowercase English lettero). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
xx...oo.x...oox.
YES
x.oxox..x.o.oo.x
NO
x..x..ooo...x.xo
YES
o.x.o....x..ooxx
NO
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
题目大意:
给你一个初始的图,问你能否在一步操作中x取得胜利
思路:
暴力模拟即可。
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;char a[10][10];int fx[8]={1,-1,0,0,1,-1,1,-1};int fy[8]={0,0,1,-1,1,-1,-1,1};int judge(){ for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { if(a[i][j]=='x') { for(int z=0;z<8;z++) { int flag=0; for(int k=1;k<=2;k++) { int xx=i+fx[z]*k; int yy=j+fy[z]*k; if(xx>=0&&xx<4&&yy>=0&&yy<4) { if(a[xx][yy]=='x')continue; else flag=1; } else flag=1; } if(flag==0)return 1; } } } } return 0;}int main(){ memset(a,'.',sizeof(a)); for(int i=0;i<4;i++) { scanf("%s",a[i]); } int flag=0; for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { if(a[i][j]=='.') { a[i][j]='x'; int tmp=judge(); a[i][j]='.'; if(tmp==1)flag=1; } } } if(flag==1)printf("YES\n"); else printf("NO\n");}
- Codeforces Round #390(Div. 2)B. Ilya and tic-tac-toe game【模拟】
- Codeforces Round #390 (Div. 2)-B Ilya and tic-tac-toe game(模拟)
- Codeforces Round #390 (Div. 2) B. Ilya and tic-tac-toe game(dfs)
- Codeforces Round #390 (Div. 2)B Ilya and tic-tac-toe game
- Codeforces #390 (Div. 2) B. Ilya and tic-tac-toe game ( DFS
- 【Codeforces 754 B Ilya and tic-tac-toe game】
- 【codeforces 754B】 Ilya and tic-tac-toe game
- codeforces 754 B Ilya and tic-tac-toe game
- CodeForces 754B Ilya and tic-tac-toe game
- B. Ilya and tic-tac-toe game
- Codeforces-754B-Ilya and tic-tac-toe game(简单模拟判断)
- Cdoeforces 754 B - Ilya and tic-tac-toe game
- 754B Ilya and tic-tac-toe game
- 754B. Ilya and tic-tac-toe game
- 2017寒假集训-小题训练1:F - Ilya and tic-tac-toe game
- Codeforces Beta Round #3 / 3C Tic-tac-toe (超级模拟)
- 001 tic-tac-toe game
- C. Tic-tac-toe【模拟】
- POJ 2796 Feel Good 【单调栈】
- 常见排序算法 - 快速排序 (Quick Sort)
- application framework层
- Codeforces Round #390(Div. 2)A. Lesha and array splitting【思维】
- 三、DC/OS运行spark
- Codeforces Round #390(Div. 2)B. Ilya and tic-tac-toe game【模拟】
- Android 性能监控与分析方法
- GiraphV1.1与V1.2之磁盘读写比较
- java-小功能-生产二维码
- sublime使用技巧
- 欢迎使用CSDN-markdown编辑器
- Python的类方法,静态方法,实例方法,类变量,实例变量,静态变量的总结
- Unity动画系统-给人物添加动画
- 微信开发出现“该公众号暂时无法提供服务,请稍后再试”的坑