一开始太蠢,犯迷糊了,以为先确定一个轴再考虑其他的旋转,后来想想,其实只要骰子的3个对面都相同,绕一个轴转肯定可以转回来。
在实现自己的想法的时候,wa了两次,就觉得自己的想法是错的,搜了一下其他人的代码,发现都是穷举,结构体没有学好,不想写那么长,还是自己懒吧,就改了一下,竟然就AC了,好开心。所以只要思路正确,就一直写下去,不要被别人的思想给同化,代码嘛,自己怎么懒,怎么写。
We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors. The cube's faces are numbered as in Figure 1.
Figure 1.
Since a cube has 6 faces, our machine can paint a face-numbered cube in different ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a b, r, or g. The
character (
) from the left gives the color of face i. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds to rggbgr. Notice that both cubes are painted in the same way: by rotating it around the vertical axis by 90
, the one changes into the other.
Input
The input of your program is a textfile that ends with the standard end-of-file marker. Each line is a string of 12 characters. The first 6 characters of this string are the representation of a painted cube, the remaining 6 characters give you the representation of another cube. Your program determines whether these two cubes are painted in the same way, that is, whether by any combination of rotations one can be turned into the other. (Reflections are not allowed.)
Output
The output is a file of boolean. For each line of input, output contains TRUE if the second half can be obtained from the first half by rotation as describes above, FALSE otherwise.
Sample Input
rbgggrrggbgr rrrbbbrrbbbr rbgrbgrrrrrg
Sample Output
TRUE FALSE FALSE题面就是这个,虽说是个水题,但是我自己的方法就是好啊,你咬我啊!
贴代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
char a[12];
int flag=0;
while(scanf("%s",a)!=EOF)
{
int i,j;
for(i=0;i<6;i++)
for(j=6;j<12;j++)
if(a[i]==a[j]&&a[5-i]==a[17-j]&&a[i]!=0&&a[j]!=0&&a[5-i]!=0&&a[17-j]!=0)
{
flag++;
a[i]=a[j]=a[5-i]=a[17-j]=0;
}
if(flag==3) printf("TRUE\n");
if(flag!=3) printf("FALSE\n");
flag=0;
}
return 0;
}
多训练思维,暴力是没有办法的办法。