题解 UVA253 【Cube painting】
模拟题,就是固定向上和下面不变,旋转其余四个面,每次改变向上的面,就会枚举所有6*4个不同的姿态,再与第二个骰子比较,要点空间想象力,不行拿个称手的东西比划下就出来了,还有旋转时注意下姿态。
#include<bits/stdc++.h>
using namespace std; //列出不同面朝上是各个位置的数字
int dir[6][6] = { { 0, 1, 2, 3, 4, 5 }, { 1, 0, 3, 2, 5, 4 }, { 2, 0, 1, 4, 5, 3 }, { 3, 0, 4, 1, 5, 2 }, { 4, 0, 2, 3, 5, 1 }, { 5, 1, 3, 2, 4, 0 } };
char a[10],b[10],s[20];
bool judge()
{
for (int i=0;i<6;i++)
{
char temp[10]="";
for (int j=0;j<6;j++) //置骰子姿态分别为各个不同数字向上
temp[j]=a[dir[i][j]];
for (int j=0;j<4; j++)
{
char c_temp;
c_temp=temp[1]; //旋转,注意yy出旋转是数字变化的方式
temp[1]=temp[2];
temp[2]=temp[4];
temp[4]=temp[3];
temp[3]=c_temp;
if (strcmp(temp,b)==0) return true;
}
}
return false;
}
int main()
{
while (scanf("%s",s)!=EOF)
{
for (int i=0;i<6;i++)
a[i]=s[i];
a[6]=0;
for (int i=0;i<6;i++)
b[i]=s[i+6];
b[6]=0;
if (judge()) cout<<"TRUE"<<endl;
else cout<<"FALSE"<<endl;
}
}