题意
给一个正方体各个面图上色,让后再给一个涂过色的正方体,问后者是不是前者旋转而来的。
分析
对于同一个正方形,如果确定了两个面,就确定了一个它的各个面。那么让通过旋转枚举各个面分别成为正面的情况,再旋转四个侧面确定顶面,就可枚举出所有情况(共
为方便枚举,用数组记录置换来模拟旋转(如代码)
AC代码
//UVA 253 Cube painting
//2016-7-20 20:10:56
//Math
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <list>
#include <sstream>
#include <stack>
using namespace std;
#define cls(x) memset(x,0,sizeof x)
#define inf(x) memset(x,0x3f,sizeof x)
#define neg(x) memset(x,-1,sizeof x)
#define ninf(x) memset(x,0xc0,sizeof x)
#define st0(x) memset(x,false,sizeof x)
#define st1(x) memset(x,true,sizeof x)
#define INF 0x3f3f3f3f
#define lowbit(x) x&(-x)
#define bug cout<<"here"<<endl;
//#define debug
const char rot1[][7]={"123456","513462","263415","142536","135246","154326"};
const char rot2[][7]={"123456","421653","326154","624351"};
char org[7],test[7],cur1[7],cur2[7];
void rotate1(char a[],char b[],int x)
{
for(int i=0;i<6;++i)
b[i]=a[rot1[x][i]-'0'-1];
return;
}
void rotate2(char a[],char b[],int x)
{
for(int i=0;i<6;++i)
b[i]=a[rot2[x][i]-'0'-1];
return;
}
int main()
{
#ifdef debug
freopen("E:\Documents\code\input.txt","r",stdin);
freopen("E:\Documents\code\output.txt","w",stdout);
#endif
while((org[0]=getchar())!=EOF)
{
for(int i=1;i<6;++i)
org[i]=getchar();
for(int i=0;i<6;++i)
test[i]=getchar();
org[6]=test[6]=' ';
getchar();
bool found=0;
for(int i=0;i<6;++i)
{
for(int j=0;j<4;++j)
{
rotate1(org,cur1,i);
rotate2(cur1,cur2,j);
if(strcmp(cur2,test)==0)
{
found=1;
break;
}
}
if(found)
break;
}
if(found)
printf("TRUE
");
else
printf("FALSE
");
}
return 0;
}