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. 【Tomcat】tomcat设置http文件下载,配置文件下载目录

    tomcat作为http的下载服务器,网上有很多办法 但我认为最简单的是:(亲测有效) 1.直接把文件放在 /var/lib/tomcat6/webapps/ROOT 目录下, 2.然后在网址中访问: ...

  2. java中的matches -> 完全匹配

    matches是完全匹配.跟matcher不一样, matcher像perl正则, 能匹配到符合的都会返回true, 而这个matches要完全一模一样才行. import java.util.reg ...

  3. windows安装linux虚拟机、修改apt源

    记录一下windows安装虚拟机以及初始配置的一些坑. 安装VMware Workstation 直接百度搜索VMware,选择合适的版本下载: 按照一般软件的安装步骤安装VMware Worksta ...

  4. 从LabVIEW到C++

    前言 最近一段时间一直没有更新,一方面是时间精力的问题(PS:懒癌犯了),另一方面是小黑大部分的时间都在学习C++相关知识,恶补了许多的知识(从大学C语言水平强制拔高了一段). 本文谈谈自己近期的一些 ...

  5. YAML中使用Jinja模板以{{ foo }}开头需要整行加双引号

    YAML陷阱 YAML语法要求如果值以{{ foo }}开头的话我们需要将整行用双引号包起来.这是为了确认你不是想声明一个YAML字典.该知识点在 YAML 语法 页面有所讲述. 这样是不行的: - ...

  6. UFLDL 教程学习笔记(六)主成分分析

    教程:http://ufldl.stanford.edu/tutorial/supervised/MultiLayerNeuralNetworks/ 以及这篇博文,写的很清楚:http://blog. ...

  7. WP主题模板制作修改教程

    WP主题模板制作修改教程 实际上,当我们打开某个主题的文件夹时,看到的并不止这两个文件,而是更多.但一般来说,在一个完整的 WP 主题文件夹中都应该包含下列文件(也称为模板文件):页面 模板文件 用途 ...

  8. 使用360对app安全进行加固

    在写了第一个app之后,打算上架到各个渠道看看,无意间看到了360的app加固工具 http://jiagu.360.cn/ 自己体验了一把,加固过程很傻瓜化, 加固好了之后,还要对app进行二次签名 ...

  9. Asp.net vNext 学习之路(一)

    概述 asp.net vNext 也叫 asp.net 5.0,意思是微软推出的下一个版本的asp.net.可以说是微软对asp.net的一个比较重大的重新设计, asp.net vNext是一 个比 ...

  10. vuejs学习——vue+vuex+vue-router项目搭建(一)

    前言 快年底了却有新公司邀请了我,所以打算把上家公司的学到一下技术做一些总结和分享. 现在vuejs都2.0了,我相信也有很多朋友和我一样实际项目还是选择vue1.0的或者给新手一些参考,不管在选择哪 ...