B.Ilya and tic-tac-toe game(B.llya和井字棋游戏)

B. Ilya and tic-tac-toe game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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
Copy
xx..
.oo.
x...
oox.
output
YES
input
Copy
x.ox
ox..
x.o.
oo.x
output
NO
input
Copy
x..x
..oo
o...
x.xo
output
YES
input
Copy
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.

翻译:

B.llya和井字棋游戏

时间限制2秒;

空间限制256mb;

常规输入输出;

llay是个玩4×4井字游戏很有经验的玩家。他总是玩x符号。他今天和他的朋友Arseny玩了很多把。他的朋友累了,没能完成剩下的比赛。当他离开的时候,轮到llay下了。确定llay能否只下一步赢得比赛。

4×4的井字棋规矩如下。在第一个回合之前,所有的格都是空的。两个玩家轮流把自己的棋子下如空格内(第一个玩家下“x”,第二个玩家下“o”)。下“x”的玩家先下,另一个后下。谁的三个标记最先在一条直线上并且连在一起谁就赢了(水平的,垂直的,对角线的)。

输入

输入的井字棋有四行。

每行有四个格。每个格包括“.”(表示空的)。“x”(小写字母x)。或“o”(小写字母o)。这就保证它可以玩井字棋。现在轮到llay了(特别的是,这表示游戏还没有结束)。有可能所有的格都是空的,这表示朋友一个没下就走了。

输出

输出一行:如果llay能赢输出“Yes”,否则输出“No”;

例子
输入
Copy
xx..
.oo.
x...
oox.
输出
YES
输入
Copy
x.ox
ox..
x.o.
oo.x
输出
NO
输入
Copy
x..x
..oo
o...
x.xo
输出
YES
输入
Copy
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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值