首页 > 其他分享 >UVa 253 Cube painting (模拟)

UVa 253 Cube painting (模拟)

时间:2023-04-12 13:07:18浏览次数:49  
标签:11 cube str int Cube && judge UVa painting


253 - Cube painting

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=189

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, org. 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

Sample Input

rbgggrrggbgrrrrbbbrrbbbr
rbgrbgrrrrrg


Sample Output


TRUEFALSE
FALSE



枚举每个对面,再旋转比较剩下4个面,注意顺序。


完整代码:

#include <iostream>
using namespace std;

char str[15];

int judge(int a, int b, int c, int d, int e, int f)
{
	if (str[a] == str[0] && str[b] == str[5])
	{
		if (str[1] == str[c] && str[3] == str[d] && str[4] == str[e] && str[2] == str[f]) return true;
		if (str[1] == str[d] && str[3] == str[e] && str[4] == str[f] && str[2] == str[c]) return true;
		if (str[1] == str[e] && str[3] == str[f] && str[4] == str[c] && str[2] == str[d]) return true;
		if (str[1] == str[f] && str[3] == str[c] && str[4] == str[d] && str[2] == str[e]) return true;
		return false;
	}
	return false;
}

int main()
{
	while (cin >> str)
	{
		if (judge(6, 11, 7, 9, 10, 8)
		||judge(11, 6, 10, 9, 7, 8)
		||judge(7, 10, 11, 9, 6, 8)
		||judge(10, 7, 6, 9, 11, 8)
		||judge(8, 9, 11, 7, 6, 10)
		||judge(9, 8, 6, 7, 11, 10)) 
            cout << "TRUE" << endl;
		else cout << "FALSE" << endl;
	}
}



标签:11,cube,str,int,Cube,&&,judge,UVa,painting
From: https://blog.51cto.com/u_5535544/6185472

相关文章

  • UVa 11498 Division of Nlogonia (water ver.)
    11498-DivisionofNlogoniaTimelimit:1.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2493TheProblemAftercenturiesofhostilitiesandskirmishesbetweenthefour......
  • UVa 11723 Numbering Roads (water ver.)
    11723-NumberingRoadsTimelimit:1.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2823Inmycountry,streetsdon’thavenames,eachofthemarejustgivenanumber......
  • UVa 10719 Quotient Polynomial (数学)
    10719-QuotientPolynomialTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1660Apolynomialofdegree n canbeexpressedasIf k isanyintegerthenwecan......
  • UVa 103 Stacking Boxes (DP&DAG)
    103-StackingBoxesTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=39BackgroundSomeconceptsinMathematicsandComputerSciencearesimpleinoneortw......
  • UVa 11129 An antiarithmetic permutation (构造题&想法题&分治)
    11129-AnantiarithmeticpermutationTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=2070Apermutationof n+1 isabijectivefunctionoftheinitial n+1......
  • UVa 10041 Vito's Family (中位数&快速选择)
    10041-Vito'sFamilyTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=982BackgroundTheworld-knowngangsterVitoDeadstoneismovingtoNewYork.He......
  • UVa 706 / POJ 1102 LCD Display (模拟)
    706-LCDDisplayTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=647http://poj.org/problem?id=1102Afriendofyouhasjustboughtanewcomputer.Untilno......
  • UVa 757 / POJ 1042 / East Central North America 1999 Gone Fishing (枚举&贪心&想
    757-GoneFishingTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=698http://poj.org/problem?id=1042Johnisgoingonafishingtrip.Hehas h hoursavailable( ),andther......
  • UVa 408 Uniform Generator (最大公约数&证明)
    408-UniformGeneratorTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=349Computersimulationsoftenrequirerandomnumbers.Onewaytogeneratepseudo-r......
  • UVa 350 Pseudo-Random Numbers (伪随机数的循环长度)
    350-Pseudo-RandomNumbersTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=286Computersnormallycannotgeneratereallyrandomnumbers,butfrequentlyar......