HDOJ 5292 Pocket Cube 构造


.......

HDOJ 5292 Pocket Cube 构造_第1张图片

Pocket Cube

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 6    Accepted Submission(s): 3


Problem Description
Pocket Cube is the 2×2×2 equivalent of a Rubik’s Cube(3×3×3). The cube consists of 8 pieces, all corners. (from wiki)
HDOJ 5292 Pocket Cube 构造_第2张图片

It was a Pocket Cube. Unfortunately, the Cube fell to the ground and broke. It took you some time to explore the construction of the Cube. Then you assembled the Pocket Cube. Unfortunately, you didn’t assembled it in the right way. So here is the question. You want to know whether it can return to the right position.

The right position means four blocks in each face has the same color. You can only rotate the Cube to return it to the right position.

A Cube is given in its layout.
HDOJ 5292 Pocket Cube 构造_第3张图片

HDOJ 5292 Pocket Cube 构造_第4张图片

The right position rotates in red face clockwisely. 
You can get more details from input case.
w represents white , y represents yellow , o represents orange , r represents red , g represents green , b represents blue. In the right position, white and yellow , orange and red , green and blue are in the opposite face. 
 

Input
The first line of input contains only one integer T(<=10000), the number of test cases. 
Each case contains a Pocket Cube described above. After each case , there is a blacnk line.  It guarantees that the corners of the Cube is right.
 

Output
Each case contains only one line. Each line should start with “Case #i: ”,with i implying the case number, followed by “YES” or “NO”,”YES” means you can return it to the right position, otherwise “NO”.
 

Sample Input
 
   
2 g y g y o o w g r r o o w g r r b w b w y b y b r w g b b y o w o r y g y o g b r w o y b r w g
 

Sample Output
 
   
Case #1: YES Case #2: NO
 

Source
2015 Multi-University Training Contest 1
 



/* ***********************************************
Author        :CKboss
Created Time  :2015年07月21日 星期二 19时08分35秒
File Name     :HDOJ5292.cpp
************************************************ */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

int val[24]={1,-1,-1,1,-1,1,0,0,-1,1,1,-1,0,0,1,-1,1,-1,-1,1,0,0,0,0};
char str[200];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	int T_T,cas=1;

	scanf("%d",&T_T);
	getchar();
	while(T_T--)
	{
		int cnt=0,ans=0;
		for(int i=0;i<8;i++) 
		{
			gets(str);
			int sz=strlen(str);
			if(sz==0) { i--;  continue; }
			for(int j=0;j='a'&&str[j]<='z')
				{
					if(str[j]=='w'||str[j]=='y')
					{
						ans+=val[cnt];
					}
					cnt++;
				}
			}
		}

		printf("Case #%d: ",cas++);
		if(ans%3==0) puts("YES");
		else puts("NO");
	}
    
    return 0;
}


你可能感兴趣的:(想法技巧)