HDU5983Pocket Cube
Pocket Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 19 Accepted Submission(s): 8
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.
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 |
+ - + - +
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
YES
YES
YES
NO
#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的更多相关文章
- postgresql中的CUBE函数
数据函数简介添加汇总额外信息 数据 --复杂统计函数 CREATE TABLE t3 (color_type varchar(20), in_date varchar(30),color_count ...
- HDU 3584 Cube (三维 树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3584 Cube Problem Description Given an N*N*N cube A, ...
- SQLSERVER中的ALL、PERCENT、CUBE关键字、ROLLUP关键字和GROUPING函数
SQLSERVER中的ALL.PERCENT.CUBE关键字.ROLLUP关键字和GROUPING函数 先来创建一个测试表 USE [tempdb] GO )) GO INSERT INTO [#te ...
- 轻量级OLAP(一):Cube计算
有一个数据多维分析的任务: 日志的周UV: APP的收集量及标注量,TOP 20 APP(周UV),TOP 20 APP标注分类(周UV): 手机机型的收集量及标注量,TOP 20 机型(周UV),T ...
- BI cube的前世今生:商业智能BI为什么需要cube技术
企业中常常会出现这样一幕幕尴尬的场景: 企业的决策人员需要从不同的角度来审视业务,协助他们分析业务,例如分析销售数据,可能会综合时间周期.产品类别.地理分布.客户群类等多种因素来考量.IT人员在每一个 ...
- [译]Dynamics AX 2012 R2 BI系列-Cube概览
https://msdn.microsoft.com/EN-US/library/dd252604.aspx Cube是一个多维度的结构,它是BI应用开发的基础.本文描述了cube的组成部分, ...
- 【MCU】【STM32】1.cube MX库使用笔记
STM32Cube 是一个全面的软件平台,包括了ST产品的每个系列.(如,STM32CubeF4 是针对STM32F4系列). 平台包括了STM32Cube 硬件抽象层和一套的中间件组件(RTOS, ...
- STM32 Cube固件库编程之新建工程
Cube固件库是ST现在主推的固件库,并且在它的官网已经找不到原来的标准库可供下载.Cube固件库的构架图如下 这种新式构架可以有效的加快软件工程师的工程进度. 新建一个工程项目主要包括以下的步骤: ...
- 原创跑酷小游戏《Cube Duck Run》 - - 方块鸭快跑
自从unity5出来才开始关注unity,业余时间尝试做了个小游戏: <方块鸭快跑> (Cube Duck Run) 像素风,3d视角,色彩明快,有无尽和关卡两种模式. 应用连接: goo ...
随机推荐
- LeetCode 33. Search in Rotated Sorted Array(在旋转有序序列中搜索)
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...
- windows中通过bat批处理打开exe文件
1.想要运行的程序: C:\Program Files\Windows Media Player\wmplayer.exe C:\Program Files\Haihaisoft Universal ...
- echarts2.2.7本地搭建
1.首先下载echarts2.2.7,解压到本地,解压后的目录如下: 2.在WebContent下建立一个名为build的目录,复制echarts2.2.7下面的build下面的dist目录到ecli ...
- 【经验分享】Trachtenberg system(特拉亨伯格速算系统)
二战期间,俄国的数学家Jakow Trachtenberg(1888-1953)被关进纳粹集中营,在狱中,他开发出了一套心算算法,这套算法后来被命名为Trachtenberg(特拉亨伯格)速算系统. ...
- C#使用Oracle.ManagedDataAccess.dll
在刚接触C#的时候由于公司使用的就是Oracle数据库,那么C#怎么连接Oracle数据库就成了首要去掌握的知识点了.在那时没有ODP.NET,但visual studio却对Oralce数据库的调用 ...
- [转]移动前端开发之viewport的深入理解
今天去面试,被问到一个用了一万次的东西,然而我并不了解具体是个毛毛,看这一篇豁然开朗. DevicePixelRatio 以及这句话:移动设备上的viewport分为layout viewport ...
- 使用NPOI导出图片到EXCEL
1.首先引用NPOI 2.本例用到的引用 3.在Controller里面添加导出方法 public ActionResult ExportMsgData(string term) { //为list赋 ...
- netty常用使用方式
最近在重新看netty,在这里总结一些netty的一些常用的使用方式,类似于模板,方便速查. 以netty 4.1.x的API作记录,不同版本可能API有略微差异,需要注意netty5被废弃掉了(辨别 ...
- 在微信端使用video标签,播放结束会出现QQ浏览器推荐视频的解决办法(vue)
会出现播放结束显示QQ浏览器推荐视频的原因:(我是vue的项目,而且我是新手,只是单纯的给大家分享一个方法,代码比较low请自动忽略) 因为在x5(QQ浏览器)内核中,把video标签劫持了,只要是检 ...
- Android开发之漫漫长途 Ⅳ——Activity的显示之ViewRootImpl初探
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...