其他分享
首页 > 其他分享> > Cube painting UVA - 253

Cube painting UVA - 253

作者:互联网

 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.

在这里插入图片描述

 Since a cube has 6 faces, our machine can paint a face-numbered cube in 36 =729 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 i-th character (1≤ i ≤6) 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 Figure 1 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

HINT

   暴力AC是真的爽啊!!!一开始的想法是将一个正方形分成3个环形的面,然后以一个为标准另一个正方体的面为对照,一共有3!=6种组合方式。自我感觉是没有啥毛病的,但是从udebug上的数据发现了好几个错误,修改了半天一直修不好。然后果断放弃幻想直接暴力。

暴力方法:

  无论一个正方体怎么旋转6个面还是6个面,将所有的6个面的一种情况列出来,然后上底面和下底面固定时又对应四种情况再次列举出来。直接利用循环判断每一种情况,暴力解决。

Accepted

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

//6个面分别位于上底面时的其中一种情况
int arr[6][6] = { {1,2,3,4,5,6},{2,6,3,4,1,5},{3,2,6,1,5,4},{4,2,1,6,5,3},{5,1,3,4,6,2},{6,5,3,4,2,1} };
//上底面和下地面固定对应的4种情况
int arr1[4][6] = { {1,2,3,4,5,6},{1,3,5,2,4,6},{1,4,2,5,3,6},{1,5,4,3,2,6} };

void translate(char* temp, char* s, int* arr2)
{
	for (int i = 0;i < 6;i++)
		temp[i] = s[arr2[i] - 1];
}

int main()
{
	char s[13];
	while (scanf("%s", s) != EOF)
	{
		char s1[7] = { 0 };
		char s2[7] = { 0 };
		strncpy(s1, s, 6);	//将两个立方体区分开来
		strncpy(s2, s+6, 6);
		int flag = 0;
		for (int i = 0;i < 6;i++)
		{
			char temp[7] = { 0 };
			char temp1[7] = { 0 };
			translate(temp, s1, arr[i]);//先找到一种情况
			for (int j = 0;j < 4;j++)
			{
				translate(temp1, temp, arr1[j]);//判断着一种情况对应的4个状态
				if (strncmp(temp1, s2, 6) == 0)
				{
					flag = 1;
					break;
				}
			}
			if (flag)break;
		}
		printf("%s\n", flag == 1 ? "TRUE" : "FALSE");
	}
}
			}
		}
		if (flag)break;
	}
	printf("%s\n", flag == 1 ? "TRUE" : "FALSE");
}

}


标签:cube,FALSE,temp,int,char,flag,Cube,UVA,painting
来源: https://blog.csdn.net/qq_45988416/article/details/113195832