【codeforces 754B】 Ilya and tic-tac-toe game
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的更多相关文章
- 【55.70%】【codeforces 557A】Ilya and Diplomas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【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 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 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 ...
- POJ 2361 Tic Tac Toe
题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...
- 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 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
随机推荐
- 洛谷 P1724 东风谷早苗
P1724 东风谷早苗 题目描述 在幻想乡,东风谷早苗是以高达控闻名的高中生宅巫女.某一天,早苗终于入手了最新款的钢达姆模型.作为最新的钢达姆,当然有了与以往不同的功能了,那就是它能够自动行走,厉害吧 ...
- 1.12 Python基础知识 - 序列:字符串
字符串是一个有序的字符集合,即字符序列.Pythpn内置数据类型str,用于字符串处理,使用单引号或双引号括起来的字符,就是字符常量,Python解释器会自动创建str型对象实例. 字符串的定义: 1 ...
- windows.location属性(常用知识点)
location对象 含有当前URL的信息. 属性 href 整个URL字符串.protocol 含有URL第一部分的字符串,如http:host 包含有URL中主机名:端口号部分的字符串.如//ww ...
- pt模型
top-down
- [D3] Add hovercard
The way to add hovercard is Append a div with class 'hovercard' in the tick function, positioning th ...
- Android 网络图片Url 转 Bitmap
注意:该方法必须要在子线程中调用,因为涉及网络请求 public Bitmap getBitmap(String url) { Bitmap bm = null; try { URL iconUrl ...
- Day1:用户交互与格式化输出
一.用户交互 1.input()方法 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan username = inpu ...
- 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)
[链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...
- NPF
NPF是一个协议驱动.从性能方面来看,这不是最好的选择,但是它合理地独立于MAC层并且有权使用原始通信 (raw traffic).NPF是Winpcap的核心部分,它是Winpcap完成困难工作的组 ...
- 【Codeforces Round #440 (Div. 2) C】 Maximum splitting
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 肯定用尽量多的4最好. 然后对4取模的结果 为0,1,2,3分类讨论即可 [代码] #include <bits/stdc++ ...