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. ASP.NET Core 开源GitServer 实现自己的GitHub

    ASP.NET Core 2.0 开源Git HTTP Server,实现类似 GitHub.GitLab. GitHub:https://github.com/linezero/GitServer ...

  2. containing block和BFC

    1.Box Box 是 CSS 布局的对象和基本单位,元素的类型和 display 属性,决定了这个 Box 的类型.比较常见的有: block-level box:display 属性为 block ...

  3. 用ajax的同步请求解决登陆注册需要根据服务器返回数据判断是否能提交的问题

    最近在写www.doubilaile.com的登陆注册.需要用ajax请求服务器判断用户名是否存在,用户名和密码是否匹配,进而提交数据.碰到的问题是异步请求都能成功返回数据,但是该数据不能作为紧接着的 ...

  4. IDEA搭建SSMM框架(详细过程)

    IDEA搭建SSMM框架(详细过程) 相关环境 Intellij IDEA Ultimate Tomcat JDK MySql 5.6(win32/win64) Maven (可使用Intellij ...

  5. 线上Mysql数据库崩溃事故的原因和处理

    前文提要 承接前文<一次线上Mysql数据库崩溃事故的记录>,在文章中讲到了一次线上数据库崩溃的事件记录,建议两篇文章结合在一起看,不至于摸不着头脑. 由于时间原因,其中只讲了当时的一些经 ...

  6. 【Arduino】使用LCD1602和DHT11制作温湿度显示器

    材料: 1.DHT11 2.LCD1602 3.LCD1602 转接板 4.Arduino UNO 5.Arduino 传感器扩展版 那个Arduino UNO 我当初挑类个便宜的山寨货买,结果发来和 ...

  7. padding-使用必记

    前言 说起了padding可谓是盒子模型中最常用的一个属性,你真的了解padding吗?那我请问您设置padding会影响盒子的宽度与高度吗?也许好多人会回答padding会影响到盒子的宽度与高度.在 ...

  8. IpHelper根据客户端IP进行网站分流

    public class IpHelper    {        // 核心方法:IP搜索       /// <summary>        /// 查找IP所属地区,确保web.c ...

  9. 约瑟夫环C#解决方法

    /*约瑟夫环 (问题描述) 约瑟夫问题的一种描述是:编号为1,2,......n,的n个人按顺时针方向围坐一圈,每个人持有一个密码(正整数).一开始任意选 一个正整数作为报数的上限值m,从第一个人开始 ...

  10. linux下curl的地址使用双引号引用的原因

    只知道这么使用,加上双引号,原因不太清楚 原因在于加上双引号可以防止转义,在linux中使用&会使进程后台运行,必须对&进行转义,加反斜杠的方式比较麻烦,故使用双引号模式最方便.