time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

【题目链接】:http://codeforces.com/contest/754/problem/B

【题解】



枚举那个X放在那个空位;

放了之后;

枚举哪一个X是连续三个X中间那个;如果找到了符合要求的就输出有解;

(复杂度很高吧;但是那么小,怎么搞都能过了);



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); char s[9];
int a[10][10]; bool sear_ch()
{
rep1(i,1,4)
rep1(j,1,4)
if (a[i][j]==1)
{
if (j-1>=1 && j+1<=4)
if (a[i][j-1]==a[i][j] && a[i][j]==a[i][j+1])
return true;
if (i-1>=1 && i+1<=4)
if (a[i+1][j]==a[i][j] && a[i][j]==a[i-1][j])
return true;
if (i-1>=1 && j-1>=1 && i+1<=4 && j+1<=4)
if (a[i-1][j-1]==a[i][j] && a[i][j]==a[i+1][j+1])
return true;
if (i-1>=1 && j+1<=4 && i+1<=4 && j-1>=1)
if (a[i-1][j+1]==a[i][j] && a[i][j]==a[i+1][j-1])
return true;
}
return false;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
rep1(i,1,4)
{
scanf("%s",s+1);
rep1(j,1,4)
if (s[j]=='x')
a[i][j] = 1;
else
if (s[j]=='o')
a[i][j] = 0;
else
a[i][j] = -1;
}
rep1(i,1,4)
rep1(j,1,4)
if (a[i][j]==-1)
{
a[i][j]=1;
if (sear_ch())
{
puts("YES");
return 0;
}
a[i][j]=-1;
}
puts("NO");
return 0;
}

【codeforces 754B】 Ilya and tic-tac-toe game的更多相关文章

  1. 【55.70%】【codeforces 557A】Ilya and Diplomas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【leetcode】1275. Find Winner on a Tic Tac Toe Game

    题目如下: Tic-tac-toe is played by two players A and B on a 3 x 3 grid. Here are the rules of Tic-Tac-To ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. Principle of Computing (Python)学习笔记(7) DFS Search + Tic Tac Toe use MiniMax Stratedy

    1. Trees Tree is a recursive structure. 1.1 math nodes https://class.coursera.org/principlescomputin ...

  5. POJ 2361 Tic Tac Toe

    题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...

  6. 2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe

    题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...

  7. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  8. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. 常见c#正则表达式类学习整理

    1.MatchCollection类 用于输入字符串所找到的成功匹配的集合,Regex.Matches 方法返回 MatchCollection 对象 用法 //str:要搜索匹配项的字符串 patt ...

  2. Android控件:RadioButton(单选button)

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...

  3. TextView-shadow 阴影实现

    直接上代码 1)实现普通效果 <TextView android:layout_width="match_parent" android:layout_height=&quo ...

  4. 编码与乱码(05)---GBK与UTF-8之间的转换--转载

    原文地址:http://www.blogjava.net/pengpenglin/archive/2010/02/22/313669.html [GBK转UTF-8] 在很多论坛.网上经常有网友问“  ...

  5. [D3] Build an Area Chart with D3 v4

    Similar to line charts, area charts are great for displaying temporal data. Whether you’re displayin ...

  6. Netty系列之Netty可靠性分析--转载

    原文地址:http://www.infoq.com/cn/articles/netty-reliability 1. 背景 1.1. 宕机的代价 1.1.1. 电信行业 毕马威国际(KPMG Inte ...

  7. C#委托与事件(生动故事)

    [委托] 1,工人Peter按工作步骤向老板报告的程序. 程序: using System; using System.Collections.Generic; using System.Linq; ...

  8. Library Component Properties的表格如何填写

  9. 【例题 6-16 UVa 10129】Play on Words

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 入度减去出度个数为1的点和为-1的点各有1个,然后其他点入度减去出度为0 或者全都是入度为0的点即可. [代码] #include ...

  10. 算法 Tricks(三)—— 数组(序列)任意区间最小(大)值

    序列(数组)的区间通过左右端点确定,这样首先设置一个最值变量用来记录最值,从左端点一步步移动到右端点,自然移动的过程中也可以计算整个区间的和,也即一次线性遍历下来,可同时获得多个有用信息. // 区间 ...