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.oxox..x.o.oo.x

output

NO

input

x..x..ooo...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 }
时间: 2024-10-12 17:12:55

Codeforces Round #390 (Div. 2) B的相关文章

Codeforces Round #390 (Div. 2) 解题报告

时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing383简直人生巅峰…… 看楼上楼下都是两道题的 如果A题不错那么多估计能进前300了吧…… 这场倒是把之前两场的分加回来了 开头不错 这个假期争取紫名~ A.Lesha and array splitting 把给定的数组分割成几个区间 要求各个区间和不能为0 一开始没注意到分割之后的区间重新合成之

Codeforces Round #390 (Div. 2)

22:35-0:35  1.6.2017 A.Lesha and array splitting 题意:自己看 题解: 构造什么的最弱了 想了想,貌似除了0每个数单独一组就可以,只要有一个非0数则一定可以有解 0的话不停往前找到第一个非0然后合为一组 第一个数是0怎么办?先让第一个数往后找一个非0呗 比赛的时候智商骤减,写的代码好难看还写了好长时间,并且还WA一次...应该可以很简洁的吧 #include<iostream> #include<cstdio> #include<

Codeforces Round #390 (Div. 2) D

All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has 

Codeforces Round #390 (Div. 2) A B C D

这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性质 所以如果不全是0 最后一定是有答案的 把所有的0都合并到最近的非0数上去 非0数不变 #include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> #include<

Codeforces Round #390 (Div. 2) A

One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我