UVa253骰子涂色

本文讲述了如何解决UVa253题目中关于骰子涂色的旋转等价判断问题。作者最初陷入误解,后来通过穷举方法实现,强调思路正确的重要性,并给出了输入输出格式和样例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一开始太蠢,犯迷糊了,以为先确定一个轴再考虑其他的旋转,后来想想,其实只要骰子的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.

picture21

Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in tex2html_wrap_inline126 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 br, or g. The tex2html_wrap_inline128 character ( tex2html_wrap_inline130 ) 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 tex2html_wrap_inline134 , the one changes into the other.

tex2html_wrap138 tex2html_wrap140

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;
}
多训练思维,暴力是没有办法的办法。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值