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 346. Moving Average from Data Stream (数据流动中的移动平均值)$
Given a stream of integers and a window size, calculate the moving average of all integers in the sl ...
- ios微信支付 v3
V2版本和V3版本存在很大的差异. 1. 从成功通过微信支付商户的资料审核返回的邮件开始: 你可以获得这些参数 appid,appSecret,partnerID, partnerKey(从平 ...
- HBase数据备份及恢复(导入导出)的常用方法
一.说明 随着HBase在重要的商业系统中应用的大量增加,许多企业需要通过对它们的HBase集群建立健壮的备份和故障恢复机制来保证它们的企业(数据)资产.备份Hbase时的难点是其待备份的数据集可能非 ...
- 采访 Lua 发明人的一篇文章
采访 Lua 发明人的一篇文章 来源 https://blog.codingnow.com/2010/06/masterminds_of_programming_7_lua.html <Mast ...
- 1016: [JSOI2008]最小生成树计数
1016: [JSOI2008]最小生成树计数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 6200 Solved: 2518[Submit][St ...
- 数组删除操作 splice
原理通过设置 函数的 length 属性 var a = [1, 2, 3, 4]; a.length = 3 ; 结果 : a = [1,2,3]
- 学Java的前景与就业,资深程序员教你怎么开始学Java!
IT行业一直是就业的热门岗位,程序员这个职业稳定性和收入比都有着不错的前景,那么学Java的前景和就业是什么样的呢?随着入行Java的准程序员越来越多,各种学习Java的流派也层出不穷!其实在编程的世 ...
- URL模块之parse方法
url.parse(urlString , boolean , boolean) parse这个方法可以将一个url的字符串解析并返回一个url的对象. 参数: urlString指传入一个url地址 ...
- 两个Xml转换为DataSet方法(C#)
///通过传入的特定XML字符串,通过 ReadXml函数读取到DataSet中.protected static DataSet GetDataSetByXml(string xmlData){ ...
- 使用dynamic特性处理XML文档
处理XML文档是我们经常需要进行的一项工作,尤其是在进行网络服务相关编程时,比如更新RSS等.在.NET 3.5中引入了Linq To XML,使得XML文档的读写已经大大简化,而.NET 4.0中最 ...