首页 > 其他分享 >Codeforces887C-Solution for Cube

Codeforces887C-Solution for Cube

时间:2022-11-22 20:03:45浏览次数:95  
标签:begin cube end NO Solution writeln flag Codeforces887C Cube


C. Solution for Cube



time limit per test



memory limit per test



input



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



ai (1 ≤ ai), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.



Output



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:



Codeforces887C-Solution for Cube_C


In second test case cube looks like this:



Codeforces887C-Solution for Cube_codeforces_02


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.




标签:begin,cube,end,NO,Solution,writeln,flag,Codeforces887C,Cube
From: https://blog.51cto.com/u_15888102/5878412

相关文章

  • Solution - ARC152D Halftree
    首先\(n\)为偶数时无解,这是显然的,因为一次加两条边,总边数一定是偶数。下面我们证明\(n\)为奇数时一定有解,直接进行构造。首先将每一个点编号加上\(k\)再模\(n\)......
  • Solution Set -「LGR-126」洛咕咕的 NOIP 模拟赛
      机房在三楼,不在五楼.  三楼确实有阶梯教室.  三楼向外望是一楼大厅屋顶所以看上去不高.  十一点前必须离开科技楼是因为爱因斯坦要锁大门.  我不会被自......
  • STM32CubeMX处理UTF-8编码中文注释存在的问题及解决方法
    STM32CubeMX处理UTF-8编码中文注释存在的问题及解决方法Windows环境下源代码使用UTF-8编码,STM32CubeMX创建的源文件中包含中文注释,那么使用STM32CubeMX重新生成源代码时会导......
  • STM32CubeMX+Keil5环境创建
    1、打开桌面的STM32CubMX软件2、点击File→NewProject创建新的项目 3、选择合适的芯片型号,因为本人是F103ZET6,故选择,双击确定。4、选择合适调试接口 5、将外部......
  • CF1744F MEX vs MED Solution
    看到\(\text{mex}>\text{med}\),想到一定满足\([0,\text{med}]\)都在区间内出现过。那么考虑枚举\(\text{med}\),对于每一个\(\text{med}\)计算答案。每次加入一个新......
  • Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo can
    项目启动时报错:Causedby:org.hibernate.HibernateException:AccesstoDialectResolutionInfocannotbenullwhen'hibernate.dialect'notset 正常情况下,如果不......
  • cube ui 中 cube-scroll、cube-slide 问题总结
    嵌套点击事件重复解决方案DOM<cube-slide><cube-slide:options="slideOptions"/></cube-slide>computedslideOptions(){return{......
  • Solution Set -「NOIP Simu.」20221113
    \(\mathscr{A}\sim\)游戏  Cover:「ARC087E」Prefix-freeGame.  Tags:「A.博弈-SG函数」「A.数据结构-Trie」  想了半天(\(\ge15~\text{min}\))怎么表述一......
  • L10U5-2-Finding a solution to a problem
    L10U5-2-FindingasolutiontoaproblemReadingBrainstormingtipsReadthetextaboutbrainstormingtipsandanswerthequestions.BrainstormingtipsBrainsto......
  • 优化Cube,除了剪枝还可以这么做
    优化Cube,除了剪枝还可以这么做坚持原创,写好每一篇文章对于Cube的性能优化,除了使用对Cube剪枝外,还有其他的策略,比如及时清理没有用的Segment等,这篇文章就说说除了Cube剪......