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. LeetCode 485. Max Consecutive Ones (最长连续1)

    Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...

  2. MySql数据库的基本原理及指令

    1.什么是数据库 数据库就是存储数据的仓库,其本质是一个文件系统,数据按照特定的格式将数据存储起来,用户可以通过SQL对数据库中的数据进行增加,修改,删除及查询操作. 2.简介 MySQL是一个开放源 ...

  3. HDU 5791 Two(训练题002 F)

    Description Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A' and ...

  4. CSS3详解:transform、transition

    CSS3 transform是什么? transform的含义是:改变,使-变形:转换 CSS3 transform都有哪些常用属性? transform的属性包括:rotate() / skew() ...

  5. JAVA 后台SSM框架接收安卓端的json数据

    最近项目上与安卓端做JSON数据交互,使用的SSM框架,刚开始的时候感觉很简单,想着不就是把安卓端的JSON数据封装为Bean类对象吗? 于是就这样写了 可是这样一直报400,百度原因是因为请求url ...

  6. QT中槽的使用

    一.建立槽和按钮之间的连接 connect(信号发送者,发送的信号,信号接收者,信号接收者的槽函数) 1.例子 connect(ui->pushButton,SIGNAL(clicked(boo ...

  7. 用大白话扯扯那"神奇"的面向对象编程思维(一)

    前言: 每当提到面向对象的时候,初学者肯定都是一脸懵逼的状态,到底什么是面向对象?会用面向对象后有什么牛逼之处吗?不会用是不是就会死掉?答案肯定不会死掉,我们可以来简单的举一 个栗子 1.当你想到熊猫 ...

  8. python+selenium安装

    1.下载Python 请到官网自行下载安装https://www.python.org/downloads/ 在安装的时候,注意一定要勾上这个选项,可以免去我们配置系统变量的麻烦,如果你忘了,没关系, ...

  9. mapbox-gl象形文字字体glyph生成

    简介 mapbox-gl可以对文字显示各种字体(依赖ttf文件),内部采用的是读取protobuf文件 环境条件 硬件:mac.网络 软件:nodejs.npm 创建mapbox-gl可用的字体pro ...

  10. 一:Tomcat 服务器 在45秒内未启动成功

    myeclipse或者eclipse中 tomcat 启动超时怎么办?     修改文件     找到Eclipse的工作空间\.metadata\.plugins\org.eclipse.wst.s ...