【】【】Pocket Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 47 Accepted Submission(s): 12
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
【题目链接】:http://acm.split.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=737
【题解】
各个面在数组中的下标如下
然后让他旋转一次就好;
看看各个面是不是变成一样了;
不旋转也是可以的.
【完整代码】
#include <bits/stdc++.h>
using namespace std;
int c[6][4],temp[6][4];
bool ok(int a[6][4])
{
for (int i = 0;i <= 5;i++)
{
for (int j = 1;j <= 3;j++)
if (a[i][j]!=a[i][j-1])
return false;
}
return true;
}
void fuzhi(int a[6][4],int b[6][4])
{
for (int i = 0;i <= 5;i++)
for (int j = 0;j <= 3;j++)
a[i][j] = b[i][j];
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--)
{
for (int i = 0;i <= 5;i++)
for (int j = 0;j<= 3;j++)
scanf("%d",&c[i][j]),temp[i][j] = c[i][j];
if (ok(temp))
{
puts("YES");
continue;
}
int t0,t1;
fuzhi(temp,c);
temp[1][0] = temp[4][1],temp[1][1] = temp[4][3];
temp[4][3] = temp[3][2],temp[4][1] = temp[3][3];
temp[3][2] = temp[5][0],temp[3][3] = temp[5][2];
temp[5][0] = c[1][1],temp[5][2] = c[1][0];
if (ok(temp))
{
puts("YES");
continue;
}
fuzhi(temp,c);
temp[1][0] = temp[5][2],temp[1][1] = temp[5][0];
temp[5][2] = temp[3][3],temp[5][0] = temp[3][2];
temp[3][3] = temp[4][1],temp[3][2] = temp[4][3];
temp[4][1] = c[1][0],temp[4][3] = c[1][1];
if (ok(temp))
{
puts("YES");
continue;
}
fuzhi(temp,c);
temp[1][1] = temp[0][1],temp[1][3] = temp[0][3];
temp[0][1] = temp[3][1],temp[0][3] = temp[3][3];
temp[3][1] = temp[2][1],temp[3][3] = temp[2][3];
temp[2][1] = c[1][1],temp[2][3] = c[1][3];
if (ok(temp))
{
puts("YES");
continue;
}
fuzhi(temp,c);
temp[1][1] = temp[2][1],temp[1][3] = temp[2][3];
temp[2][1] = temp[3][1],temp[2][3] = temp[3][3];
temp[3][1] = temp[0][1],temp[3][3] = temp[0][3];
temp[0][1] = c[1][1],temp[0][3] = c[1][3];
if (ok(temp))
{
puts("YES");
continue;
}
fuzhi(temp,c);
temp[5][2] = temp[0][2],temp[5][3] = temp[0][3];
temp[0][2] = temp[4][2],temp[0][3] = temp[4][3];
temp[4][2] = temp[2][1],temp[4][3] = temp[2][0];
temp[2][1] = c[5][2],temp[2][0] = c[5][3];
if (ok(temp))
{
puts("YES");
continue;
}
fuzhi(temp,c);
temp[5][2] = temp[2][1],temp[5][3] = temp[2][0];
temp[2][1] = temp[4][2],temp[2][0] = temp[4][3];
temp[4][2] = temp[0][2],temp[4][3] = temp[0][3];
temp[0][2] = c[5][2],temp[0][3] = c[5][3];
if (ok(temp))
{
puts("YES");
continue;
}
puts("NO");
}
return 0;
}
最新文章
- idea转eclipse 设置注意。
- jQuery基本选择器
- Spring第12篇—— Spring对Hibernate的SessionFactory的集成功能
- 看完com本质论第一章
- Linux解压/压缩命令——tar、gz、tar.gz、tgz、bz2、tar.bz2、Z、zip、rar、lha
- POJ3297+map字符串处理
- 基于visual Studio2013解决算法导论之046广度优先搜索
- 程序缩小到托盘后系统就无法关机(解决方案)——处理WM_QUERYENDSESSION消息,并把它标识为处理过了
- 安卓常用 widget
- python爬虫第一天
- 如何做更好的Android驱动project师
- Java实现 中文转换成Unicode编码 和 Unicode编码转换成中文
- 【Spring源码分析】原型Bean实例化过程、byName与byType及FactoryBean获取Bean源码实现
- dataframe去除null、NaN和空字符串
- iOS 小米推送总结和遇到的坑
- 从零开始学spring cloud(八) -------- Eureka 高可用机制
- Windows批处理命令学习中遇到的坑--持续更新中
- Python运维开发:初识Python(一)
- R语言修改标题、坐标轴刻度、坐标轴名称的大小(cex.axis、cex.lab、cex.main函数)
- 第五节《Git基本操作》
热门文章
- php高并发秒杀解决方案
- ";C:\Program Files\Internet Explorer\iexplore.exe"; -extoff 无加载项启动IE 浏览器打开时全屏模式
- easy ui 验证
- Android Material风格的应用(四)--FloatActionButton
- sql基础知识集锦
- Altium Designer中原理图和pcb交叉查找
- jvisualvm 工具使用
- 【Codeforces Round #440 (Div. 2) B】Maximum of Maximums of Minimums
- angular管道相关知识
- 删除GitHub上项目中的某个文件