模拟
题意
给骰子涂色,用rbg表示颜色,骰子可以通过旋转变成一致
[ UVA - 253 (VJ) ]
思路
一开始思路很卡,枚举有误,借鉴了大神的思路才过
模拟骰子,固定两个面为底面不动(6种情况),剩下四个面旋转(4种情况),即可模拟枚举出4*6=24种情况
AC代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define maxn 20
char s[maxn],s1[maxn],s2[maxn];
int dr[6][6]={ {0,1,2,3,4,5},{5,4,2,3,1,0},{1,5,2,3,0,4},{4,0,2,3,5,1},{2,1,5,0,4,3},{3,1,0,5,4,2} }; //固定两个底的6种情况
void spin( char s2[], int a, int b, int c, int d ) //旋转 (*4)
{
char t;
t = s2[a];
s2[a] = s2[b];
s2[b] = s2[c];
s2[c] = s2[d];
s2[d] = t;
}
int judge()
{
char temp[maxn] = {0};
for(int i = 0; i < 6; i++)
{
for(int j = 0; j < 6; j++)
temp[j] = s1[dr[i][j]];
for( int j = 0; j < 4; j++ ){
spin( temp, 1, 2, 4, 3 );
if( strcmp(temp,s2) == 0 )
return 1;
}
}
return 0;
}
int main()
{
while( scanf("%s",s) != EOF )
{
for( int i = 0 ; i < 6 ; i++ )
s1[i] = s[i];
for( int i = 0 ; i < 6 ; i++ )
s2[i] = s[i+6];
if( judge() ) puts("TRUE");
else puts("FALSE");
}
return 0;
}