Codeforces887C-Solution for Cube

C. Solution for Cube
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.

It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.

To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.

Cube is called solved if for each face of cube all squares on it has the same color.

https://en.wikipedia.org/wiki/Rubik's_Cube

Input

In first line given a sequence of 24 integers ai (1 ≤ ai ≤ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.

Output

Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.

Examples
input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
output
NO
input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
output
YES
Note

In first test case cube looks like this:

In second test case cube looks like this:

It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.

题意:给一个二阶魔方,问能否转一次让它完成。直接 模拟。
Code:
var
  i,j,sum:longint;flag:boolean;
  a:array[1..6,1..4] of longint;
  f:array[1..6] of boolean;
begin
  for i:=1 to 6 do
  begin
    for j:=1 to 4 do read(a[i][j]);
    if (a[i][1]=a[i][2])and(a[i][1]=a[i][3])and(a[i][1]=a[i][4]) then
    begin
      f[i]:=true;
      inc(sum);
    end;
  end;
  if sum<>2 then writeln('NO') else
  begin
    if (f[1])and(f[3]) then
    begin
      flag:=true;
      for i:=1 to 6 do
        if (a[i][1]<>a[i][2])or(a[i][3]<>a[i][4]) then
          flag:=false;
      if flag then
      begin
        if ((a[4][1]=a[2][3])and(a[2][1]=a[5][3])and(a[5][1]=a[6][3])and(a[6][1]=a[4][3]))or
           ((a[4][3]=a[2][1])and(a[2][3]=a[5][1])and(a[5][3]=a[6][1])and(a[6][3]=a[4][1])) then
           writeln('YES') else writeln('NO');
      end else writeln('NO');
    end;
    if (f[4])and(f[5]) then
    begin
      flag:=true;
      for i:=1 to 6 do
        if (a[i][1]<>a[i][3])or(a[i][2]<>a[i][4]) then
          flag:=false;
      if flag then
      begin
        if ((a[1][1]=a[2][2])and(a[2][1]=a[3][2])and(a[3][1]=a[6][1])and(a[6][2]=a[1][2]))or
           ((a[1][2]=a[2][1])and(a[2][2]=a[3][1])and(a[3][2]=a[6][2])and(a[6][1]=a[1][1])) then
           writeln('YES') else writeln('NO');
      end else writeln('NO');
    end;
    if (f[2])and(f[6]) then
    begin
      flag:=true;
      if (a[1][1]<>a[1][2])or(a[1][3]<>a[1][4])or
         (a[3][1]<>a[3][2])or(a[3][3]<>a[3][4])or
         (a[4][1]<>a[4][3])or(a[4][2]<>a[4][4])or
         (a[5][1]<>a[5][3])or(a[5][2]<>a[5][4]) then flag:=false;
      if flag then
      begin
        if ((a[1][1]=a[5][1])and(a[5][2]=a[3][1])and(a[3][3]=a[4][2])and(a[4][1]=a[1][3]))or
           ((a[1][3]=a[5][2])and(a[5][1]=a[3][3])and(a[3][1]=a[4][1])and(a[4][2]=a[1][1])) then
           writeln('YES') else writeln('NO');
      end else writeln('NO');
    end;
  end;
end.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jack-Oran

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值