【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子列的个数; 然后让你输出 ...
随机推荐
- 【Codeforces Round #451 (Div. 2) D】Alarm Clock
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法+二分. 类似滑动窗口. 即左端点为l,右端点为r. 维护a[r]-a[l]+1总是小于等于m的就好. (大于m就右移左端点) ...
- Windows(x86,64bit)升级MySQL 5.7.17免安装版的详细教程
MySQL需要升级到5.5.3以上版本才支持Laravel 5.4默认的utf8mb64字符编码.因此就把MySQL升级了一下,期间还是遇到些小问题,记录一下以供参考. 升级准备 备份之前MySql目 ...
- wechat4j框架具体解释
发送消息: 基于上面access_token的逻辑,在构造发送消息对象的时候请依照例如以下代码. wechat4j和微信强力推荐的方法 CustomerMsg customerMsg = new Cu ...
- 1.1 Introduction中 Producers官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Producers 生产者(Producers) Producers publish ...
- Android网络框架OkHttp之get请求(源码初识)
概括 OkHttp现在很火呀.于是上个星期就一直在学习OkHttp框架,虽然说起来已经有点晚上手了,貌似是2013年就推出了.但是现在它版本更加稳定了呀.这不,说着说着,OkHttp3.3版本在这几天 ...
- 韦东山网课https://edu.csdn.net/course/play/207/1117
接口讲解https://edu.csdn.net/course/play/207/1117
- 学习笔记:Vue——处理边界情况
访问元素&组件 01.访问根实例 $root // Vue 根实例 new Vue({ data: { foo: 1 }, computed: { bar: function () { /* ...
- js日期常用方法
js获取日期时间格式 export function formatDateTime(timeStamp) { var date = new Date(); date.setTime(timeStamp ...
- Oracle学习总结(9)—— Oracle 常用的基本操作
创建用户,相当于在sqlServer中创建一个数据库 create user 用户名 identified by 密码 修改用户密码 alter user 用户名 identified by 新 ...
- java线程——详解Callable、Future和FutureTask
回顾: 接上篇博客 java线程--三种创建线程的方式,这篇博客主要介绍第三种方式Callable和Future.比较继承Thread类和实现Runnable接口,接口更加灵活,使用更广泛.但这两种方 ...