Pocket Cube

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5292

Description

Pocket Cube is the 2×2×2 equivalent of a Rubik’s Cube(3×3×3). The cube consists of 8 pieces, all corners. (from wiki)

It was a Pocket Cube. Unfortunately, the Cube fell to the ground and broke. It took you some time to explore the construction of the Cube. Then you assembled the Pocket Cube. Unfortunately, you didn’t assembled it in the right way. So here is the question. You want to know whether it can return to the right position.

The right position means four blocks in each face has the same color. You can only rotate the Cube to return it to the right position.

A Cube is given in its layout.

The right position rotates in red face clockwisely.

You can get more details from input case.

w represents white , y represents yellow , o represents orange , r represents red , g represents green , b represents blue. In the right position, white and yellow , orange and red , green and blue are in the opposite face.

Input

The first line of input contains only one integer T(<=10000), the number of test cases.

Each case contains a Pocket Cube described above. After each case , there is a blacnk line. It guarantees that the corners of the Cube is right.

Output

Each case contains only one line. Each line should start with “Case #i: ”,with i implying the case number, followed by “YES” or “NO”,”YES” means you can return it to the right position, otherwise “NO”.

Sample Input

2

g y

g y

o o w g r r

o o w g r r

b w

b w

y b

y b

r w
g b

b y o w o r

y g y o g b

r w

o y

b r

w g

Sample Output

Case #1: YES

Case #2: NO

Hint

题意

给你一个二阶魔方,然后问你是否能够还原。

题解:

(黄色,白色),(绿色,蓝色),(红色,橙色)为对面色。每个角块为这三个集合中各取出一种颜色的组合。共8种。如图(1)所示,为每个方格附上权值。当该方格为黄色或白色时(其他对色组也可),加上方格上的权值。总和为3的倍数时可还原,否则不可以。必要性:从一个已经还原好的魔方出发,初始权值和为三的倍数。在旋转一个面的时候,权值和mod3不会发生变化。充分性:局部调整法。对于相邻的角块,可进行图(2)和图(3)不改变其他角块的变化。还原7个块后,mod3不变,第8块也已还原。

不要问我为什么,直接看题解……

代码

#include<bits/stdc++.h>
using namespace std; string s;
int a[]={1,-1,-1,1,-1,1,0,0,-1,1,1,-1,0,0,1,-1,1,-1,-1,1,0,0};
int main()
{
int t;scanf("%d",&t);
for(int cas=1;cas<=t;cas++)
{
int ans = 0;
for(int i=0;i<24;i++)
{
cin>>s;
if(s[0]=='w'||s[0]=='y')
ans+=a[i];
}
printf("Case #%d: ",cas);
if(ans%3==0)printf("YES\n");
else printf("NO\n");
}
}

HDU 5292 Pocket Cube 结论题的更多相关文章

  1. HDU 4801 Pocket Cube

    题目链接 去年现场,虎哥1Y的,现在刷刷题,找找状态... 一共6种转法,把3个面放到顶部,左旋和右旋,感觉写的还不错....都写成常数了. #include <stdio.h> #inc ...

  2. 2013区域赛长沙赛区现场赛 K - Pocket Cube

    K - Pocket Cube Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  3. Pocket Cube

    Pocket Cube http://acm.hdu.edu.cn/showproblem.php?pid=5983 Time Limit: 2000/1000 MS (Java/Others)    ...

  4. 【】【】Pocket Cube

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s) ...

  5. [codevs5578][咸鱼]tarjan/结论题

    5578 咸鱼  时间限制: 1 s  空间限制: 128000 KB   题目描述 Description 在广袤的正方形土地上有n条水平的河流和m条垂直的河流,发达的咸鱼家族在m*n个河流交叉点都 ...

  6. BZOJ_1367_[Baltic2004]sequence_结论题+可并堆

    BZOJ_1367_[Baltic2004]sequence_结论题+可并堆 Description Input Output 一个整数R Sample Input 7 9 4 8 20 14 15 ...

  7. [BZOJ3609][Heoi2014]人人尽说江南好 结论题

    Description 小 Z 是一个不折不扣的 ZRP(Zealot Round-game Player,回合制游戏狂热玩家), 最近他 想起了小时候在江南玩过的一个游戏.     在过去,人们是要 ...

  8. 【uoj#282】长度测量鸡 结论题

    题目描述 给出一个长度为 $\frac{n(n+1)}2$ 的直尺,要在 $0$ 和 $\frac{n(n+1)}2$ 之间选择 $n-1$ 个刻度,使得 $1\sim \frac{n(n+1)}2$ ...

  9. 【uoj#175】新年的网警 结论题+Hash

    题目描述 给出一张 $n$ 个点 $m$ 条边的无向连通图,每条边的边权为1.对于每个点 $i$ ,问是否存在另一个点 $j$ ,使得对于任意一个不为 $i$ 或 $j$ 的点 $k$ ,$i$ 到 ...

随机推荐

  1. CentOS 6.5 安装 MongoDB

    1. 配置 yum 新建 /etc/yum.repos.d/mongodb-org-3.4.repo 文件,使用以下配置:(适用于 MongoDB 3.0 以后版本) [mongodb-org-3.4 ...

  2. Perl6多线程4: Promise allof / anyof

    allof   : 所有代码块执行完成后才退出 anyof :只要有一个代码块执行完后就马上退出 要配合 await 一起用: my $p = start {say 'a'}; ;say 'b';} ...

  3. pycharm双击无响应,打不开问题解决办法

    之前好好的pycharm,突然双击打不开了,怎么办? 亲测有效方案: 第一步:进入如下路径,找到cmd.exe,右键选择“以管理员身份运行”: 第二步:在打开的cmd窗口中,输入 netsh wins ...

  4. Sublime Text2使用规则

    Sublime Text是我发现的有一好用的编辑器,它不单单只支持 python ,几乎支持目前主流的语言,快捷键丰富,可以极大的提高代码开发效率.Sublime Text 网址:http://www ...

  5. centos7安装完成后的一些配置

    1.打开终端 输入 sudo yum -y update 先更新软件包 2.这是输入语言 应用程序->系统工具->设置->区域和语言->+   ->汉语(中国)-> ...

  6. redis常见数据操作

    redis中有5种常见的数据类型,针对这5种数据类型有着相应的数据操作. 1.String(键值对为String - String) set k1 v1 get k1 getset k1 v1 - h ...

  7. C++的一大误区——深入解释直接初始化与复制初始化的区别

      转自:http://blog.csdn.net/ljianhui/article/details/9245661 不久前,在博客上发表了一篇文章——提高程序运行效率的10个简单方法,对于其中最后一 ...

  8. 【前端笔记】浅谈js继承

    我们先想想我们用js最后要怎样实现面向对象的编程.事实上我们必须用上原型链这种东西. 我们的父类superType有属性和方法,并且一些能被子类subType继承,一些能被覆盖,但是丝毫不会影响到父类 ...

  9. CAS单点登陆的两个原理图

    最近学习CAS单点登录,所以在网上找了两张比较清晰的原理图以供参考: [CAS浏览器请求认证序列图] 其中:*  ST:Service Ticket,用于客户端应用持有,每个ST对应一个用户在一个客户 ...

  10. iptables配置文件

    https://www.cnblogs.com/itxiongwei/p/5871075.html