Codeforces Round #390 (Div. 2) B

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 gets three of his signs in a row next to each other (horizontal, vertical or diagonal).

Input

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 letter x), or 'o' (lowercase English letter o). 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.

Output

Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.

Examples
input
xx..
.oo.
x...
oox.
output
YES
input
x.ox
ox..
x.o.
oo.x
output
NO
input
x..x
..oo
o...
x.xo
output
YES
input
o.x.
o...
.x..
ooxx
output
NO
Note

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’,如果是连续的三个x(水平和垂直,对角线)就算胜利

解法:暴力判断

复制代码
 1 #include<bits/stdc++.h>
 2 typedef long long LL;
 3 typedef unsigned long long ULL;
 4 using namespace std;
 5 const int maxn=1e5;
 6 char Mp[10][10];
 7 int solve(){
 8     for(int i=1;i<=4;i++){
 9         for(int j=1;j<=4;j++){
10             if(Mp[i][j]=='x'&&Mp[i][j+1]=='x'&&Mp[i][j+2]=='x'&&j+2<=4){
11                 return 1;
12             }
13         }
14     }
15     for(int i=1;i<=4;i++){
16         for(int j=1;j<=4;j++){
17             if(Mp[i][j]=='x'&&Mp[i+1][j]=='x'&&Mp[i+2][j]=='x'&&i+2<=4){
18                 return 1;
19             }
20         }
21     }
22     for(int i=1;i<=4;i++){
23         for(int j=1;j<=4;j++){
24             if(Mp[i][j]=='x'&&Mp[i+1][j+1]=='x'&&Mp[i+2][j+2]=='x'&&i+2<=4&&j+2<=4){
25                 return 1;
26             }
27         }
28     }
29     for(int i=1;i<=4;i++){
30         for(int j=1;j<=4;j++){
31             if(Mp[i][j]=='x'&&Mp[i+1][j-1]=='x'&&Mp[i+2][j-2]=='x'&&i+2<=4&&j-2>=1){
32                 return 1;
33             }
34         }
35     }
36     return 0;
37 }
38 int main(){
39     for(int i=1;i<=4;i++){
40         for(int j=1;j<=4;j++){
41             cin>>Mp[i][j];
42         }
43     }
44     for(int i=1;i<=4;i++){
45         for(int j=1;j<=4;j++){
46             if(Mp[i][j]=='.'){
47                 Mp[i][j]='x';
48                 if(solve()){
49                     cout<<"YES"<<endl;
50                     return 0;
51                 }
52                 Mp[i][j]='.';
53             }
54         }
55     }
56     cout<<"NO"<<endl;
57     return 0;
58 }
复制代码

 

posted @   樱花落舞  阅读(286)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
历史上的今天:
2016-07-24 Codeforces Round #364 (Div. 2) C
点击右上角即可分享
微信分享提示