Pocket Cube

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 19    Accepted Submission(s): 8

Problem Description
The Pocket Cube, also known as the Mini Cube or the Ice Cube, is the 2 × 2 × 2 equivalence of a Rubik’s Cube.

The cube consists of 8 pieces, all corners.

Each piece is labeled by a three dimensional coordinate (h, k, l) where h, k, l ∈ {0, 1}. Each of the six faces owns four small faces filled with a positive integer.

For each step, you can choose a certain face and turn the face ninety degrees clockwise or counterclockwise.

You should judge that if one can restore the pocket cube in one step. We say a pocket cube has been restored if each face owns four same integers.
 
Input
The first line of input contains one integer N(N ≤ 30) which is the number of test cases.

For each test case, the first line describes the top face of the pocket cube, which is the common 2 × 2 face of pieces

labelled by (0, 0, 1),(0, 1, 1),(1, 0, 1),(1, 1, 1). Four integers are given corresponding to the above pieces.

The second line describes the front face, the common face of (1, 0, 1),(1, 1, 1),(1, 0, 0),(1, 1, 0). Four integers are

given corresponding to the above pieces.

The third line describes the bottom face, the common face of (1, 0, 0),(1, 1, 0),(0, 0, 0),(0, 1, 0). Four integers are

given corresponding to the above pieces.

The fourth line describes the back face, the common face of (0, 0, 0),(0, 1, 0),(0, 0, 1),(0, 1, 1). Four integers are

given corresponding to the above pieces.

The fifth line describes the left face, the common face of (0, 0, 0),(0, 0, 1),(1, 0, 0),(1, 0, 1). Four integers are given

corresponding to the above pieces.

The six line describes the right face, the common face of (0, 1, 1),(0, 1, 0),(1, 1, 1),(1, 1, 0). Four integers are given

corresponding to the above pieces.

In other words, each test case contains 24 integers a, b, c to x. You can flat the surface to get the surface development

as follows.

+ - + - + - + - + - + - +
| q | r | a | b | u | v |
+ - + - + - + - + - + - +
| s | t | c | d | w | x |
+ - + - + - + - + - + - +
| e | f |
+ - + - +
| g | h |
+ - + - +
| i | j |
+ - + - +
| k | l |
+ - + - +
| m | n |
+ - + - +
| o | p |
+ - + - +
 
Output
For each test case, output YES if can be restored in one step, otherwise output NO.
 
Sample Input
4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
6 6 6 6
1 1 1 1
2 2 2 2
3 3 3 3
5 5 5 5
4 4 4 4
1 4 1 4
2 1 2 1
3 2 3 2
4 3 4 3
5 5 5 5
6 6 6 6
1 3 1 3
2 4 2 4
3 1 3 1
4 2 4 2
5 5 5 5
6 6 6 6
 
Sample Output
YES
YES
YES
NO
 

解题思路:
自己叠了一个简易的立方体,就能看出魔方的每个面坐标变换的规则,直接模拟的,暂时没有什么好的方法。QAQ

源代码:
#include<iostream>
#include<string>
#include<set>
#include<cstdio>
#include<cstring>
using namespace std;
int ans[9][9];
void readdata() {
memset(ans,-1,sizeof(ans));
for(int i=1;i<=8;i++)
for(int j=3;j<=4;j++)
scanf("%d",&ans[i][j]);
for(int i=1;i<=2;i++)
for(int j=1;j<=2;j++)
scanf("%d",&ans[i][j]);
for(int i=1;i<=2;i++)
for(int j=5;j<=6;j++)
scanf("%d",&ans[i][j]);
}
/*是否已经是还原成功的模样*/
int check(int c[9][9]) {
int i,j;
i=1,j=3;if(c[i][j]!=c[i][j+1]||c[i][j]!=c[i+1][j]||c[i][j]!=c[i+1][j+1])return 0;
i=3,j=3;if(c[i][j]!=c[i][j+1]||c[i][j]!=c[i+1][j]||c[i][j]!=c[i+1][j+1])return 0;
i=5,j=3;if(c[i][j]!=c[i][j+1]||c[i][j]!=c[i+1][j]||c[i][j]!=c[i+1][j+1])return 0;
i=7,j=3;if(c[i][j]!=c[i][j+1]||c[i][j]!=c[i+1][j]||c[i][j]!=c[i+1][j+1])return 0;
i=1,j=1;if(c[i][j]!=c[i][j+1]||c[i][j]!=c[i+1][j]||c[i][j]!=c[i+1][j+1])return 0;
i=1,j=5;if(c[i][j]!=c[i][j+1]||c[i][j]!=c[i+1][j]||c[i][j]!=c[i+1][j+1])return 0;
return 1;
}
/*总共出现的数字超过了6个*/
int cnt() {
set<int> s;s.clear();
for(int i=1;i<=8;i++)
for(int j=3;j<=4;j++)
s.insert(ans[i][j]);
for(int i=1;i<=2;i++)
for(int j=1;j<=2;j++)
s.insert(ans[i][j]);
for(int i=1;i<=2;i++)
for(int j=5;j<=6;j++)
s.insert(ans[i][j]);
return s.size();
}
/*检查竖列的两个方向*/
int linecheck() {
int sum=0;
int bns[9][9];
for(int i=1;i<=8;i++)
for(int j=1;j<=8;j++)
bns[i][j]=ans[i][j];
int temp1,temp2;
/*up*/
temp1=bns[1][3];
temp2=bns[2][3];
for(int i=1;i<=6;i++) {
bns[i][3]=bns[i+2][3];
}
bns[7][3]=temp1;
bns[8][3]=temp2;
if(check(bns)) sum+=1;
/*down*/
for(int i=1;i<=8;i++)
for(int j=1;j<=8;j++)
bns[i][j]=ans[i][j];
temp1=bns[7][3];
temp2=bns[8][3];
for(int i=8;i>=3;i--) {
bns[i][3]=bns[i-2][3];
}
bns[1][3]=temp1;
bns[2][3]=temp2;
if(check(bns)) sum+=1;
return sum;
}
/*检查横向的两个方向*/
int rowcheck() {
int sum=0;
int bns[9][9];
for(int i=1;i<=8;i++)
for(int j=1;j<=8;j++)
bns[i][j]=ans[i][j];
int temp1,temp2;
/*right*/
temp1=bns[6][3];
temp2=bns[6][4];
bns[6][3]=bns[1][6];
bns[6][4]=bns[1][5];
for(int i=6;i>=3;i--)
bns[1][i]=bns[1][i-2];
bns[1][1]=temp2;
bns[1][2]=temp1;
if(check(bns)) sum+=1;
/*left*/
for(int i=1;i<=8;i++)
for(int j=1;j<=8;j++)
bns[i][j]=ans[i][j];
temp1=bns[6][3];
temp2=bns[6][4];
bns[6][3]=bns[1][2];
bns[6][4]=bns[1][1];
for(int i=1;i<=4;i++)
bns[1][i]=bns[1][i+2];
bns[1][5]=temp2;
bns[1][6]=temp1;
if(check(bns)) sum+=1;
return sum;
}
int exdir() {
int sum=0;
int bns[9][9];
for(int i=1;i<=8;i++)
for(int j=1;j<=8;j++)
bns[i][j]=ans[i][j];
int temp1,temp2;
/*dir-left*/
temp1=bns[8][3];
temp2=bns[8][4];
bns[8][3]=bns[1][5];bns[8][4]=bns[2][5];
bns[1][5]=bns[3][4];bns[2][5]=bns[3][3];
bns[3][3]=bns[1][2];bns[3][4]=bns[2][2];
bns[1][2]=temp2;bns[2][2]=temp1;
if(check(bns)) sum+=1;
/*dir-right*/
for(int i=1;i<=8;i++)
for(int j=1;j<=8;j++)
bns[i][j]=ans[i][j];
temp1=bns[8][3];
temp2=bns[8][4];
bns[8][3]=bns[2][2];bns[8][4]=bns[1][2];
bns[1][2]=bns[3][3];bns[2][2]=bns[3][4];
bns[3][3]=bns[2][5];bns[3][4]=bns[1][5];
bns[1][5]=temp1;bns[2][5]=temp2;
if(check(bns)) sum+=1;
return sum;
}
int main() {
int t;scanf("%d",&t);
while(t--) {
int flag=0;
readdata();
/*总共出现的数字超过了6个*/
if(cnt()!=6) {
printf("NO\n");continue;
}
/*是否已经是还原成功的模样*/
if(check(ans)==1) {
printf("YES\n");continue;
}
/*检查竖列的两个方向*/
if(linecheck()) {
printf("YES\n");continue;
}
/*检查横向的两个方向*/
if(rowcheck()) {
printf("YES\n");continue;
}
/*ex-dir另外两个方向*/
if(exdir()) {
printf("YES\n");continue;
}
/*上面所有情况都不符合*/
if(!flag)
printf("NO\n");
}
return 0;
}

HDU5983Pocket Cube的更多相关文章

  1. postgresql中的CUBE函数

    数据函数简介添加汇总额外信息 数据 --复杂统计函数 CREATE TABLE t3 (color_type varchar(20), in_date varchar(30),color_count ...

  2. HDU 3584 Cube (三维 树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3584 Cube Problem Description Given an N*N*N cube A,  ...

  3. SQLSERVER中的ALL、PERCENT、CUBE关键字、ROLLUP关键字和GROUPING函数

    SQLSERVER中的ALL.PERCENT.CUBE关键字.ROLLUP关键字和GROUPING函数 先来创建一个测试表 USE [tempdb] GO )) GO INSERT INTO [#te ...

  4. 轻量级OLAP(一):Cube计算

    有一个数据多维分析的任务: 日志的周UV: APP的收集量及标注量,TOP 20 APP(周UV),TOP 20 APP标注分类(周UV): 手机机型的收集量及标注量,TOP 20 机型(周UV),T ...

  5. BI cube的前世今生:商业智能BI为什么需要cube技术

    企业中常常会出现这样一幕幕尴尬的场景: 企业的决策人员需要从不同的角度来审视业务,协助他们分析业务,例如分析销售数据,可能会综合时间周期.产品类别.地理分布.客户群类等多种因素来考量.IT人员在每一个 ...

  6. [译]Dynamics AX 2012 R2 BI系列-Cube概览

    https://msdn.microsoft.com/EN-US/library/dd252604.aspx     Cube是一个多维度的结构,它是BI应用开发的基础.本文描述了cube的组成部分, ...

  7. 【MCU】【STM32】1.cube MX库使用笔记

    STM32Cube 是一个全面的软件平台,包括了ST产品的每个系列.(如,STM32CubeF4 是针对STM32F4系列). 平台包括了STM32Cube 硬件抽象层和一套的中间件组件(RTOS, ...

  8. STM32 Cube固件库编程之新建工程

    Cube固件库是ST现在主推的固件库,并且在它的官网已经找不到原来的标准库可供下载.Cube固件库的构架图如下 这种新式构架可以有效的加快软件工程师的工程进度. 新建一个工程项目主要包括以下的步骤: ...

  9. 原创跑酷小游戏《Cube Duck Run》 - - 方块鸭快跑

    自从unity5出来才开始关注unity,业余时间尝试做了个小游戏: <方块鸭快跑> (Cube Duck Run) 像素风,3d视角,色彩明快,有无尽和关卡两种模式. 应用连接: goo ...

随机推荐

  1. [Bayesian] “我是bayesian我怕谁”系列 - Naive Bayes+prior

    先明确一些潜规则: 机器学习是个collection or set of models,一切实践性强的模型都会被归纳到这个领域,没有严格的定义,’有用‘可能就是唯一的共性. 机器学习大概分为三个领域: ...

  2. Android 6.0运行时权限

    一.Runtime Permissions Android 6.0在手机安全方面做的一个处理就是增加了运行时权限(Runtime Permissions). 新的权限机制更好的保护了用户的隐私,Goo ...

  3. SAP开发快捷键

    F1 帮助     F2 回车确认(在某些地方可用,比如ABAP)     F3 返回     F4 选择输入项     F5 新增     F6 复制为...     F7 全选     F8 选择 ...

  4. c++の奇技淫巧

    >如何用cmd编译c++?-m32究竟是什么操作?这究竟是道德的沦丧还是人性的泯灭,请收看今日的c++奇技淫巧 咳咳,扯远了(正经脸)主要是今天学了c++的一些编译技巧以及cmd的一些操作,总结 ...

  5. Problem V

    Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that th ...

  6. nginx服务部署 说明

    第1章 常用的软件 1.1 常用来提供静态服务的软件   Apache :这是中小型Web服务的主流,Web服务器中的老大哥,   Nginx :大型网站Web服务的主流,曾经Web服务器中的初生牛犊 ...

  7. Log4j – Configuring Log4j 2 - Log4j 2的配置

    Configuration Inserting log requests into the application code requires a fair amount of planning an ...

  8. RE : 球体波浪倒计时

    背景: 移动端需要做一个倒计时球体水波的效果.主要用到了CSS的SVG瞄点动画和JS的计时器.该动画原型来自于  使用球体水面波动显示进度动画 http://wow.techbrood.com/fid ...

  9. 三、VueJs 填坑日记之项目文件认识

    上一篇博文,我们搭建了一套基础的vuejs的环境,首先安装node.js,然后利用npm包管理器,安装vue-cli,设置淘宝镜像,初始化项目,安装依赖,运行.在这一篇,我们将认识vuejs项目里的各 ...

  10. [转载] PHP工作模型与运行机制

    转载自http://www.nowamagic.net/librarys/veda/detail/350 PHP的工作模型非常特殊.从某种程度上说,PHP和ASP.ASP.NET.JSP/Servle ...