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).
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.
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
xx.. .oo. x... oox.
YES
x.ox ox.. x.o. oo.x
NO
x..x ..oo o... x.xo
YES
o.x. o... .x.. ooxx
NO
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.
翻译:
B.llya和井字棋游戏
时间限制2秒;
空间限制256mb;
常规输入输出;
llay是个玩4×4井字游戏很有经验的玩家。他总是玩x符号。他今天和他的朋友Arseny玩了很多把。他的朋友累了,没能完成剩下的比赛。当他离开的时候,轮到llay下了。确定llay能否只下一步赢得比赛。
4×4的井字棋规矩如下。在第一个回合之前,所有的格都是空的。两个玩家轮流把自己的棋子下如空格内(第一个玩家下“x”,第二个玩家下“o”)。下“x”的玩家先下,另一个后下。谁的三个标记最先在一条直线上并且连在一起谁就赢了(水平的,垂直的,对角线的)。
输入
输入的井字棋有四行。
每行有四个格。每个格包括“.”(表示空的)。“x”(小写字母x)。或“o”(小写字母o)。这就保证它可以玩井字棋。现在轮到llay了(特别的是,这表示游戏还没有结束)。有可能所有的格都是空的,这表示朋友一个没下就走了。
输出
输出一行:如果llay能赢输出“Yes”,否则输出“No”;
xx.. .oo. x... oox.
YES
x.ox ox.. x.o. oo.x
NO
x..x ..oo o... x.xo
YES
o.x. o... .x.. ooxx
NO
在第一个例子中llay有两个可以获胜的动作:左侧1列中,最左边的空格中的第一行。
在第二个例子中一步不可能赢。
在第三个例子中第四行第二列可以赢。
在第四个例子中一步不可能赢。
程序:
# include<iostream>
# include<cstdio>
# include<cstring>
using namespace std;
char cp[5][5];
int a,b,c,d,j=4,l[3]={0,0,0},q=1,z=3,v;
int main()
{
for(a=1;a<=4;a++)
for(b=1;b<=4;b++)
cin>>cp[a][b];
for(a=1;a<=4;a++)
{
if(a>2)
j=2;
for(b=1;b<=j;b++)
{
l[1]=0;l[2]=0;l[3]=0;
if(b<=2&&a<=2)
{
if(cp[a][b]!='o')
{
// if(cp[a][b]=='x')
// {
// l[1]=1;l[2]=1;l[3]=1;
// }
for(v=0;v<=2;v++)
{
if(cp[a+v][b]=='x')
l[1]++;
else if(cp[a+v][b]=='o')
l[1]--;
if(cp[a+v][b+v]=='x')
l[2]++;
else if(cp[a+v][b+v]=='o')
l[2]--;
if(cp[a][b+v]=='x')
l[3]++;
else if(cp[a][b+v]=='o')
l[3]--;cout<<l[1]<<" "<<l[3]<<" ";
}
if(l[1]==2||l[2]==2||l[3]==2) //判断是否符合条件
{
cout<<l[1]<<" "<<l[2]<<" "<<l[3];
printf("Yes\n");
return 0;
}
}
else
break;
if(a>2)
{
if(cp[a][b]!='o')
{
if(cp[a][b]=='x')
{
l[1]=1;l[2]=1;l[3]=1;
}
for(v=1;v<=2;v++)
{
if(cp[a-v][b-v]=='x')
l[2]++;
else if(cp[a-v][b-v]=='o')
l[2]--;
if(cp[a][b+v]=='x')
l[3]++;
else if(cp[a][b+v]=='o')
l[3]--;
}
}
if(l[1]>=2||l[2]>=2||l[3]>=2)
{
cout<<l[1]<<" "<<l[2]<<" "<<l[3];
printf("Yes\n");
return 0;
}
}
else
break;
}
if(b>2)
{
if(cp[a][b]!='o')
{
if(cp[a][b]=='x')
{
l[1]=1;l[2]=1;l[3]=1;
}
for(v=1;v<=2;v++)
{
if(cp[a-v][b-v]=='x')
l[2]++;
else if(cp[a-v][b-v]=='o')
l[2]--;
if(cp[a][b+v]=='x')
l[3]++;
else if(cp[a][b+v]=='o')
l[3]--;
}
}
else
break;
if(l[1]>=2||l[2]>=2||l[3]>=2)
{
cout<<l[1]<<" "<<l[2]<<" "<<l[3];
printf("Yes\n");
return 0;
}
}
/*if(a>2)
{
if(cp[a][b]!='o')
{
if(cp[a][b]=='x')
{
l[1]=1;l[2]=1;l[3]=1;
}
for(v=1;v<=2;v++)
{
if(cp[a-v][b-v]=='x')
l[2]++;
else if(cp[a-v][b-v]=='o')
l[2]--;
if(cp[a][b+v]=='x')
l[3]++;
else if(cp[a][b+v]=='o')
l[3]--;
}
}
else
break;
if(l[1]>=2||l[2]>=2||l[3]>=2)
{
cout<<l[1]<<" "<<l[2]<<" "<<l[3];
printf("Yes\n");
return 0;
}
}*/
}
}
printf("No\n");
return 0;
}