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 ...
随机推荐
- BZOJ 2843: 极地旅行社( LCT )
LCT.. ------------------------------------------------------------------------ #include<cstdio> ...
- PyQt主窗体设置停靠窗口(QDockWidget)的叠加顺序
PyQt提供了方便的停靠窗口控件,我们可以很方便的编写一个停靠窗口,代码和效果如下: # -*- coding: utf-8 -*-from PyQt4 import QtGui, QtCore cl ...
- tomcat配置管理用户名密码
tomcat6默认是将用户是注释的 配置文件在根目录下/conf/tomcat-users.xml文件中 配置默认如下: <!-- <role rolename="tomcat ...
- Deflater与Inflater的压缩与解压缩
原文:Deflater与Inflater的压缩与解压缩 package util; import java.util.Arrays; import java.util.zip.Deflater; im ...
- WPF中StringFormat 格式化 的用法
原文 WPF中StringFormat 格式化 的用法 网格用法 <my:DataGridTextColumn x:Name="PerformedDate" Header=& ...
- eclipse 找不到application选项
处理如下:Window-Preferences-Run/Debug-Perspectives 中的 And Build修改为如下
- java邮件小实例
新建一个包,名为mail 第一个类:MailSenderInfo.java ########################################### package com.util. ...
- [Andriod官方API指南]连接之蓝牙
Bluetooth —— 蓝牙 The Android platform includes support for the Bluetooth network stack, which allows ...
- HDU 5009 DP
2014 ACM/ICPC Asia Regional Xi'an Online 对于N个数 n(1 ≤ n ≤ 5×104), 把N个数分成随意个区间,每一个区间的值是该区间内不同数字个数的平方和, ...
- AsyncTask delay延迟执行 或者顺序执行 问题
惯用AsyncTask的朋友可能会发现AsyncTask的坑: Android executes AsyncTask tasks before Android 1.6 and again as of ...