POJ 1955 Rubik's Cube
暴力模拟就好了。。。。
vim写代码真费事,手都写酸了。。。
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 638 | Accepted: 324 |
Description
Rummaging through the stuff of your childhood you find an old toy which you identify as the famous Rubik's Cube. While playing around with it you have to acknowledge that throughout the years your ability to solve the puzzle has not improved a bit. But because you always wanted to understand the thing and the only other thing you could do right now is to prepare for an exam, you decide to give it a try. Luckily the brother of your girlfriend is an expert and able to fix the cube no matter how messed-up it is. The problem is that he stays with his girlfriend in the Netherlands most of the time, so you need a solution for long-distance learning. You decide to implement a program which is able to document the state of the cube and the turns to be made.
Problem
A Rubik's Cube is covered with 54 square areas called facelets, 9 facelets on each of its six sides. Each facelet has a certain color. Usually when the cube is in its starting state, all facelets belonging to one side have the same color. For the original cube these are red, yellow, green, blue, white and orange.
The positions of the facelets can be changed by turning the sides of the cube. This moves nine "little cubes" together with their attached facelets into a new position (see Fig. 1).
The problem is to determine how the facelets of the entire cube are colored after turning different sides in different directions.
Input
The starting state describes the colors of the facelets and where they are positioned. The colors are identified by single characters, and one character is given per facelet. Characters are separated by blanks and arranged in a certain pattern (see Fig. 2). The pattern identifies all six sides of the cube and can be thought of as a folding pattern. As shown in Fig. 2, the description of the top side of the cube is placed right over the description of the front side. This is done by indenting the lines with blanks. The next three lines contain the descriptions of the left, front, right and back side as shown in Fig. 2. The descriptions are simply concatenated with a blank character used as separator. After that the description of the bottom side follows, using the same format as the one used to describe the top side. This concludes the description of the starting state.
Then follows the second section of the scenario containing the turns which have to be performed. The description of the turns starts with a line containing the number of turns t (t > 0). Each turn is given in a separate line and consists of two integer values s and d which are separated by a single blank. The first value s determines the side of the cube which has to be turned. The sides are serially numbered as follows:left '0', front '1', right '2', back '3', top '4', bottom '5'. The second value d determines in which direction
the side s has to be turned and can either be '1' or '-1'. A '1' stands for clockwise and a '-1' for counterclockwise.The direction is given under the assumption that the viewer is looking directly at the specific side of the cube.
Output
Sample Input
2
w w w
w w w
w w w
r r r g g g b b b o o o
r r r g g g b b b o o o
r r r g g g b b b o o o
y y y
y y y
y y y
2
3 1
0 -1
g b b
g w w
g w w
r r r y g g b b y o o w
r r r y g g b b y o o w
w w w r g g b b y o o b
o y y
o y y
o r r
2
0 1
3 -1
Sample Output
Scenario #1:
g b b
g w w
g w w
r r r y g g b b y o o w
r r r y g g b b y o o w
w w w r g g b b y o o b
o y y
o y y
o r r Scenario #2:
w w w
w w w
w w w
r r r g g g b b b o o o
r r r g g g b b b o o o
r r r g g g b b b o o o
y y y
y y y
y y y
Source
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int mofang[60]; void SHOW()
{
int cnt=1;printf(" ");
for(int i=0;i<9;i++,cnt++)
{
printf("%c ",mofang[i]);
if(cnt%3==0)
{
if(i!=0) putchar(10);
if(i!=8) printf(" ");
}
}
cnt=1;
for(int i=9;i<45;i++,cnt++)
{
printf("%c ",mofang[i]);
if(cnt%12==0)
putchar(10);
}
cnt=1; printf(" ");
for(int i=45;i<54;i++,cnt++)
{
printf("%c ",mofang[i]);
if(cnt%3==0)
{
putchar(10);
if(i!=53) printf(" ");
}
}
putchar(10);
} void quanCLOCKwise(int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9)
{
int a,b,c;
a=mofang[a1]; b=mofang[a2]; c=mofang[a3];
mofang[a1]=mofang[a7]; mofang[a2]=mofang[a4]; mofang[a3]=a;
mofang[a7]=mofang[a9]; mofang[a4]=mofang[a8]; mofang[a8]=mofang[a6];
mofang[a6]=b; mofang[a9]=c;
} void quanFANCLOCKwise(int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9)
{
int a=mofang[a1],b=mofang[a2],c=mofang[a3];
mofang[a1]=c; mofang[a2]=mofang[a6]; mofang[a3]=mofang[a9];
mofang[a6]=mofang[a8];mofang[a9]=mofang[a7];
mofang[a7]=a; mofang[a8]=mofang[a4];mofang[a4]=b;
} void huanCLOCKwise(int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12)
{
int a=mofang[a1],b=mofang[a2],c=mofang[a3];
mofang[a1]=mofang[a10]; mofang[a2]=mofang[a11];mofang[a3]=mofang[a12];
mofang[a10]=mofang[a7];mofang[a11]=mofang[a8];mofang[a12]=mofang[a9];
mofang[a9]=mofang[a6];mofang[a8]=mofang[a5];mofang[a7]=mofang[a4];
mofang[a6]=c; mofang[a5]=b; mofang[a4]=a;
} void huanFANCLOCKwise (int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12)
{
int a=mofang[a1],b=mofang[a2],c=mofang[a3];
mofang[a1]=mofang[a4]; mofang[a2]=mofang[a5]; mofang[a3]=mofang[a6];
mofang[a4]=mofang[a7]; mofang[a5]=mofang[a8]; mofang[a6]=mofang[a9];
mofang[a9]=mofang[a12]; mofang[a8]=mofang[a11]; mofang[a7]=mofang[a10];
mofang[a10]=a; mofang[a11]=b; mofang[a12]=c;
} void QianClockwise()
{
quanCLOCKwise(12,13,14,24,25,26,36,37,38);
huanCLOCKwise(6,7,8,15,27,39,47,46,45,35,23,11);
} void QianFanClockwise()
{
quanFANCLOCKwise(12,13,14,24,25,26,36,37,38);
huanFANCLOCKwise(6,7,8,15,27,39,47,46,45,35,23,11);
} void BackClockwise()
{
quanCLOCKwise(18,19,20,30,31,32,42,43,44);
huanCLOCKwise(2,1,0,9,21,33,51,52,53,41,29,17);
} void BackFanClockwise()
{
quanFANCLOCKwise(18,19,20,30,31,32,42,43,44);
huanFANCLOCKwise(2,1,0,9,21,33,51,52,53,41,29,17);
} void LeftClockwise()
{
quanCLOCKwise(9,10,11,21,22,23,33,34,35);
huanCLOCKwise(0,3,6,12,24,36,45,48,51,44,32,20);
} void LeftFanClockwise()
{
quanFANCLOCKwise(9,10,11,21,22,23,33,34,35);
huanFANCLOCKwise(0,3,6,12,24,36,45,48,51,44,32,20);
} void RightClockwise()
{
quanCLOCKwise(15,16,17,27,28,29,39,40,41);
huanCLOCKwise(8,5,2,18,30,42,53,50,47,38,26,14);
} void RightFanClockwise()
{
quanFANCLOCKwise(15,16,17,27,28,29,39,40,41);
huanFANCLOCKwise(8,5,2,18,30,42,53,50,47,38,26,14);
} void TopClockwise()
{
quanCLOCKwise(0,1,2,3,4,5,6,7,8);
huanCLOCKwise(20,19,18,17,16,15,14,13,12,11,10,9);
} void TopFanClockwise()
{
quanFANCLOCKwise(0,1,2,3,4,5,6,7,8);
huanFANCLOCKwise(20,19,18,17,16,15,14,13,12,11,10,9);
} void BotClockwise()
{
quanCLOCKwise(45,46,47,48,49,50,51,52,53);
huanCLOCKwise(36,37,38,39,40,41,42,43,44,33,34,35);
} void BotFanClockwise()
{
quanFANCLOCKwise(45,46,47,48,49,50,51,52,53);
huanFANCLOCKwise(36,37,38,39,40,41,42,43,44,33,34,35);
} int main()
{
int t,cas=1;
scanf("%d",&t);
while(t--)
{
printf("Scenario #%d:\n",cas++);
for(int i=0;i<54;i++)
{
char c[3];
scanf("%s",c);
mofang[i]=(int)c[0];
}
int m;
scanf("%d",&m);
while(m--)
{
int a,b;
scanf("%d%d",&a,&b);
if(a==0)
{
if(b==1) LeftClockwise();
else LeftFanClockwise();
}
else if(a==1)
{
if(b==1) QianClockwise();
else QianFanClockwise();
}
else if(a==2)
{
if(b==1) RightClockwise();
else RightFanClockwise();
}
else if(a==3)
{
if(b==1) BackClockwise();
else BackFanClockwise();
}
else if(a==4)
{
if(b==1) TopClockwise();
else TopFanClockwise();
}
else if(a==5)
{
if(b==1) BotClockwise();
else BotFanClockwise();
}
}
SHOW();
}
return 0;
}
POJ 1955 Rubik's Cube的更多相关文章
- sdutoj 2606 Rubik’s cube
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2606 Rubik’s cube Time Li ...
- The Mathematics of the Rubik’s Cube
https://web.mit.edu/sp.268/www/rubik.pdf Introduction to Group Theory and Permutation Puzzles March ...
- HDU 5836 Rubik's Cube BFS
Rubik's Cube 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5836 Description As we all know, Zhu is ...
- hduoj 3459 Rubik 2×2×2
http://acm.hdu.edu.cn/showproblem.php?pid=3459 Rubik 2×2×2 Time Limit: 10000/5000 MS (Java/Others) ...
- squee_spoon and his Cube VI(贪心,找不含一组字符串的最大长度+kmp)
1818: squee_spoon and his Cube VI Time Limit: 1 Sec Memory Limit: 128 MB Submit: 77 Solved: 22Subm ...
- HDU5983Pocket Cube
Pocket Cube Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- Pocket Cube
Pocket Cube http://acm.hdu.edu.cn/showproblem.php?pid=5983 Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5292 Pocket Cube 结论题
Pocket Cube 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5292 Description Pocket Cube is the 2×2× ...
- squee_spoon and his Cube VI---郑大校赛(求最长子串)
市面上最常见的魔方,是三阶魔方,英文名为Rubik's Cube,以魔方的发明者鲁比克教授的名字命名.另外,二阶魔方叫Pocket Cube,它只有2*2*2个角块,通常也就比较小:四阶魔方叫Reve ...
随机推荐
- windows和centos用cutycapt截网页的图
centos下:(主要参考http://loosky.net/2816.html) (1)安装qt47 增加qt47的源 vim /etc/yum.repos.d/atrpms.repo //加入如下 ...
- UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现
UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现 类与类图 1) 类(Class)封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性.操作.关系的对象集合的总称. 2) 在系统中, ...
- 解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found
解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found 异常信息: The Struts dispatcher cannot be fou ...
- POJ Octal Fractions(JAVA水过)
题目链接:id=1131" target="_blank">CLICK HERE~ 尽管java一下模拟水过,可是我看到别人的一段奇妙代码,贴出和大家共享. imp ...
- java - final和static 关键字 再记忆
一.final 根据程序上下文环境,Java关键字final有“这是无法改变的”或者“终态的”含义,它可以修饰非抽象类.非抽象类成员方法和变量.你可能出于两种理解而需要阻止改变:设计或效 ...
- 基于visual Studio2013解决C语言竞赛题之0810链表去重
题目
- Boost 库Program Options--第二篇
程式執行參數處理函式庫:Boost Program Options(2/N) 前一篇已經大致解釋了 Boost Program Options 基本上的使用方法.而這一篇,則來細講一下選項描述(opt ...
- ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables opt
mysql跳过权限: mysqld -nt --skip-grant-tables opt 登录:mysql -uroot -p 修改root密码 set password for 'root'@'l ...
- MySql连接问题
今天想通过命令连接到另外一台主机的Mysql 命令: mysql -h ip -u username -p EnterPassWord: password 连接成功
- Android studio: 自 maven 增加一個函式庫
在 android studio 裏要加入一個 3rd party 的 library 其實不是很麻煩, 祇是現在沒有 UI, 所以需要一些手動作業.看來 google 很看好 android stu ...