B - Pocket Cube

链接:https://vjudge.net/contest/339839#problem/B

The Pocket Cube, also known as the Mini Cube or the Ice Cube, is the 2 × 2 × 2 equivalence of a Rubik’s Cube. 
The cube consists of 8 pieces, all corners. 
Each piece is labeled by a three dimensional coordinate (h, k, l) where h, k, l ∈ {0, 1}. Each of the six faces owns four small faces filled with a positive integer. 
For each step, you can choose a certain face and turn the face ninety degrees clockwise or counterclockwise. 
You should judge that if one can restore the pocket cube in one step. We say a pocket cube has been restored if each face owns four same integers. 

Input

The first line of input contains one integer N(N ≤ 30) which is the number of test cases. 
For each test case, the first line describes the top face of the pocket cube, which is the common 2 × 2 face of pieces 
labelled by (0, 0, 1),(0, 1, 1),(1, 0, 1),(1, 1, 1). Four integers are given corresponding to the above pieces. 
The second line describes the front face, the common face of (1, 0, 1),(1, 1, 1),(1, 0, 0),(1, 1, 0). Four integers are 
given corresponding to the above pieces. 
The third line describes the bottom face, the common face of (1, 0, 0),(1, 1, 0),(0, 0, 0),(0, 1, 0). Four integers are 
given corresponding to the above pieces. 
The fourth line describes the back face, the common face of (0, 0, 0),(0, 1, 0),(0, 0, 1),(0, 1, 1). Four integers are 
given corresponding to the above pieces. 
The fifth line describes the left face, the common face of (0, 0, 0),(0, 0, 1),(1, 0, 0),(1, 0, 1). Four integers are given 
corresponding to the above pieces. 
The six line describes the right face, the common face of (0, 1, 1),(0, 1, 0),(1, 1, 1),(1, 1, 0). Four integers are given 
corresponding to the above pieces. 
In other words, each test case contains 24 integers a, b, c to x. You can flat the surface to get the surface development 
as follows. 

+ - + - + - + - + - + - +
| q | r | a | b | u | v |
+ - + - + - + - + - + - +
| s | t | c | d | w | x |
+ - + - + - + - + - + - +
        | e | f |
        + - + - +
        | g | h |
        + - + - +
        | i | j |
        + - + - +
        | k | l |
        + - + - +
        | m | n |
        + - + - +
        | o | p |
        + - + - +

Output

For each test case, output YES if can be restored in one step, otherwise output NO.

Sample Input

4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
6 6 6 6
1 1 1 1
2 2 2 2
3 3 3 3
5 5 5 5
4 4 4 4
1 4 1 4
2 1 2 1
3 2 3 2
4 3 4 3
5 5 5 5
6 6 6 6
1 3 1 3
2 4 2 4
3 1 3 1
4 2 4 2
5 5 5 5
6 6 6 6

Sample Output

YES
YES
YES
NO

题解:不知道别人是怎么写的,俺写了700+的模拟

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
long long t,n,s=0;
long long a[10][10],b[10][10];
using namespace std;
int main()
{
    cin>>t;
    while(t--)
    {
    	for(int i=1;i<=6;i++)
    	{
    		for(int j=1;j<=4;j++)
    		cin>>a[i][j];
    	}
    	int flag=1;
    	for(int i=1;i<=6;i++)
    	{
    		if(a[i][1]==a[i][2]&&a[i][2]==a[i][3]&&a[i][3]==a[i][4])
			continue;
			else
			{
				flag=0;
				break;
			}
    	}
    	if(flag==1)
    	cout<<"YES"<<endl;
    	else
    	{
    		for(int i=1;i<=6;i++)//1
    		{
    			for(int j=1;j<=4;j++)
    			{
    				if(j%2!=0||i>=5)
    				{
    					b[i][j]=a[i][j];
    				}
    				else if(i==1)
    				{
    					b[i][j]=a[4][j];
    				}
    				else if(i==2)
    				{
    					b[i][j]=a[1][j];
    				}
    				else if(i==3)
    				{
    					b[i][j]=a[2][j];
    				}
    				else if(i==4)
    				{
    					b[i][j]=a[3][j];
    				}
    			}
    		}
	    	flag=1;
	    	for(int i=1;i<=6;i++)
	    	{
	    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
				continue;
				else
				{
					flag=0;
					break;
				}
	    	}
	    	if(flag==1)
	    	cout<<"YES"<<endl;
	    	else
	    	{
		    	for(int i=1;i<=6;i++)//2
	    		{
	    			for(int j=1;j<=4;j++)
	    			{
	    				if(j%2!=1||i>=5)
	    				{
	    					b[i][j]=a[i][j];
	    				}
	    				else if(i==1)
	    				{
	    					b[i][j]=a[4][j];
	    				}
	    				else if(i==2)
	    				{
	    					b[i][j]=a[1][j];
	    				}
	    				else if(i==3)
	    				{
	    					b[i][j]=a[2][j];
	    				}
	    				else if(i==4)
	    				{
	    					b[i][j]=a[3][j];
	    				}
	    			}
	    		}
		    	flag=1;
		    	for(int i=1;i<=6;i++)
		    	{
		    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
					continue;
					else
					{
						flag=0;
						break;
					}
		    	}
		    	if(flag==1)
		    	cout<<"YES"<<endl;
		    	else
		    	{
				    for(int i=1;i<=6;i++)//3
		    		{
		    			for(int j=1;j<=4;j++)
		    			{
		    				if(j%2!=0||i>=5)
		    				{
		    					b[i][j]=a[i][j];
		    				}
		    				else if(i==1)
		    				{
		    					b[i][j]=a[2][j];
		    				}
		    				else if(i==2)
		    				{
		    					b[i][j]=a[3][j];
		    				}
		    				else if(i==3)
		    				{
		    					b[i][j]=a[4][j];
		    				}
		    				else if(i==4)
		    				{
		    					b[i][j]=a[1][j];
		    				}
		    			}
		    		}
			    	flag=1;
			    	for(int i=1;i<=6;i++)
			    	{
			    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
						continue;
						else
						{
							flag=0;
							break;
						}
			    	}
			    	if(flag==1)
			    	cout<<"YES"<<endl;
			    	else
			    	{
				    	for(int i=1;i<=6;i++)//4
			    		{
			    			for(int j=1;j<=4;j++)
			    			{
			    				if(j%2!=1||i>=5)
			    				{
			    					b[i][j]=a[i][j];
			    				}
			    				else if(i==1)
			    				{
			    					b[i][j]=a[2][j];
			    				}
			    				else if(i==2)
			    				{
			    					b[i][j]=a[3][j];
			    				}
			    				else if(i==3)
			    				{
			    					b[i][j]=a[4][j];
			    				}
			    				else if(i==4)
			    				{
			    					b[i][j]=a[1][j];
			    				}
			    			}
			    		}
				    	flag=1;
				    	for(int i=1;i<=6;i++)
				    	{
				    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
							continue;
							else
							{
								flag=0;
								break;
							}
				    	}
				    	if(flag==1)
				    	cout<<"YES"<<endl;
				    	else
				    	{
						    for(int i=1;i<=6;i++)//5
				    		{
				    			for(int j=1;j<=4;j++)
				    			{
				    				if(i==2||i==4)
				    				{
				    					b[i][j]=a[i][j];
				    				}
				    				else if(i==1)
				    				{
				    					if(j<=2)
				    					b[i][j]=a[6][j];
				    					else
				    					b[i][j]=a[i][j];
				    				}
				    				else if(i==6)
				    				{
				    					if(j==2)
				    					{
				    						b[i][j]=a[3][3];
				    					}
				    					else if(j==1)
				    					{
				    						b[i][j]=a[3][4];
				    					}
				    					else 
				    					b[i][j]=a[i][j];
				    				}
				    				else if(i==3)
				    				{
				    					if(j==3)
				    					b[i][j]=a[5][2];
				    					else if (j==4)
				    					b[i][j]=a[5][1];
				    					else 
				    					b[i][j]=a[i][j];
				    				}
				    				else if(i==5)
				    				{
				    					if(j<=2)
				    					b[i][j]=a[1][j];
				    					else
				    					b[i][j]=a[i][j];
				    				}
				    			}
				    		}
					    	flag=1;
					    	for(int i=1;i<=6;i++)
					    	{
					    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
								continue;
								else
								{
									flag=0;
									break;
								}
					    	}
					    	if(flag==1)
					    	cout<<"YES"<<endl;
					    	else
					    	{
						    	for(int i=1;i<=6;i++)//6
					    		{
					    			for(int j=1;j<=4;j++)
					    			{
					    				if(i==2||i==4)
					    				{
					    					b[i][j]=a[i][j];
					    				}
					    				else if(i==1)
					    				{
					    					if(j>2)
					    					b[i][j]=a[6][j];
					    					else
					    					b[i][j]=a[i][j];
					    				}
					    				else if(i==6)
					    				{
					    					if(j==4)
					    					b[i][j]=a[3][1];
					    					else if(j==3)
					    					b[i][j]=a[3][2];
					    					else 
					    					b[i][j]=a[i][j];
					    				}
					    				else if(i==3)
					    				{
					    					if(j==1)
					    					b[i][j]=a[5][4];
					    					else if(j==2)
					    					b[i][j]=a[5][3];
					    					else 
					    					b[i][j]=a[i][j];
					    					
					    				}
					    				else if(i==5)
					    				{
					    					if(j>2)
					    					b[i][j]=a[1][j];
					    					else
					    					b[i][j]=a[i][j];
					    				}
					    			}
					    		}
						    	flag=1;
						    	for(int i=1;i<=6;i++)
						    	{
						    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
									continue;
									else
									{
										flag=0;
										break;
									}
						    	}
						    	if(flag==1)
						    	cout<<"YES"<<endl;
						    	else
						    	{
								    for(int i=1;i<=6;i++)//7
						    		{
						    			for(int j=1;j<=4;j++)
						    			{
						    				if(i==2||i==4)
						    				{
						    					b[i][j]=a[i][j];
						    				}
						    				else if(i==1)
						    				{
						    					if(j>2)
						    					b[i][j]=a[5][j];
						    					else
						    					b[i][j]=a[i][j];
						    				}
						    				else if(i==6)
						    				{
						    					if(j>2)
						    					b[i][j]=a[1][j];
						    					else
						    					b[i][j]=a[i][j];
						    				}
						    				else if(i==3)
						    				{
						    					if(j==1)
						    					b[i][j]=a[6][4];
						    					else if(j==2)
						    					b[i][j]=a[6][3];
						    					else
						    					b[i][j]=a[i][j];
						    				}
						    				else if(i==5)
						    				{
						    					if(j==4)
						    					b[i][j]=a[3][1];
						    					else if(j==3)
						    					b[i][j]=a[3][2];
						    					else
						    					b[i][j]=a[i][j];
						    				}
						    			}
						    		}
							    	flag=1;
							    	for(int i=1;i<=6;i++)
							    	{
							    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
										continue;
										else
										{
											flag=0;
											break;
										}
							    	}
							    	if(flag==1)
							    	cout<<"YES"<<endl;
							    	else
							    	{
								    	for(int i=1;i<=6;i++)//8
							    		{
							    			for(int j=1;j<=4;j++)
							    			{
							    				if(i==2||i==4)
							    				{
							    					b[i][j]=a[i][j];
							    				}
							    				else if(i==1)
							    				{
							    					if(j<=2)
							    					b[i][j]=a[5][j];
							    					else
							    					b[i][j]=a[i][j];
							    				}
							    				else if(i==6)
							    				{
							    					if(j<=2)
							    					b[i][j]=a[1][j];
							    					else
							    					b[i][j]=a[i][j];
							    				}
							    				else if(i==3)
							    				{
							    					if(j==3)
							    					b[i][j]=a[6][2];
							    					else if(j==4)
							    					b[i][j]=a[6][1];
							    					else 
							    					b[i][j]=a[i][j];
							    				}
							    				else if(i==5)
							    				{
							    					if(j==2)
							    					b[i][j]=a[3][3];
							    					else if(j==1)
							    					b[i][j]=a[3][4];
							    					else 
							    					b[i][j]=a[i][j];
							    				}
							    			}
							    		}
								    	flag=1;
								    	for(int i=1;i<=6;i++)
								    	{
								    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
											continue;
											else
											{
												flag=0;
												break;
											}
								    	}
								    	if(flag==1)
								    	cout<<"YES"<<endl;
								    	else
								    	{
										    for(int i=1;i<=6;i++)//9
								    		{
								    			for(int j=1;j<=4;j++)
								    			{
								    				if(i==1||i==3)
								    				{
								    					b[i][j]=a[i][j];
								    				}
								    				else if(i==5)
								    				{
								    					if(j==1)
								    					b[i][j]=a[4][2];
								    					else if(j==2)
								    					b[i][j]=a[i][j];
								    					else if(j==3)
								    					b[i][j]=a[4][1];
								    					else if(j==4)
								    					b[i][j]=a[i][j];
								    				}
								    				else if(i==4)
								    				{
								    					if(j==1)
								    					b[i][j]=a[6][2];
								    					else if(j==2)
								    					b[i][j]=a[6][4];
								    					else if(j==3)
								    					b[i][j]=a[i][j];
								    					else if(j==4)
								    					b[i][j]=a[i][j];
								    				}
								    				else if(i==6)
								    				{
								    					if(j==1)
								    					b[i][j]=a[i][j];
								    					else if(j==2)
								    					b[i][j]=a[2][4];
								    					else if(j==3)
								    					b[i][j]=a[i][j];
								    					else if(j==4)
								    					b[i][j]=a[2][3];
								    				}
								    				else if(i==2)
								    				{
								    					if(j==1)
								    					b[i][j]=a[i][j];
								    					else if(j==2)
								    					b[i][j]=a[i][j];
								    					else if(j==3)
								    					b[i][j]=a[5][1];
								    					else if(j==4)
								    					b[i][j]=a[5][3];
								    				}
								    			}
								    		}
									    	flag=1;
									    	for(int i=1;i<=6;i++)
									    	{
									    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
												continue;
												else
												{
													flag=0;
													break;
												}
									    	}
									    	if(flag==1)
									    	cout<<"YES"<<endl;
									    	else
									    	{
											    for(int i=1;i<=6;i++)//10
									    		{
									    			for(int j=1;j<=4;j++)
									    			{
									    				if(i==1||i==3)
									    				{
									    					b[i][j]=a[i][j];
									    				}
									    				else if(i==5)
									    				{
									    					if(j==1)
									    					b[i][j]=a[i][j];
									    					else if(j==2)
									    					b[i][j]=a[4][4];
									    					else if(j==3)
									    					b[i][j]=a[i][j];
									    					else if(j==4)
									    					b[i][j]=a[4][3];
									    				}
									    				else if(i==4)
									    				{
									    					if(j==1)
									    					b[i][j]=a[i][j];
									    					else if(j==2)
									    					b[i][j]=a[i][j];
									    					else if(j==3)
									    					b[i][j]=a[6][1];
									    					else if(j==4)
									    					b[i][j]=a[6][3];
									    				}
									    				else if(i==6)
									    				{
									    					if(j==1)
									    					b[i][j]=a[2][2];
									    					else if(j==2)
									    					b[i][j]=a[i][j];
									    					else if(j==3)
									    					b[i][j]=a[2][1];
									    					else if(j==4)
									    					b[i][j]=a[i][j];
									    				}
									    				else if(i==2)
									    				{
									    					if(j==1)
									    					b[i][j]=a[5][2];
									    					else if(j==2)
									    					b[i][j]=a[5][4];
									    					else if(j==3)
									    					b[i][j]=a[i][j];
									    					else if(j==4)
									    					b[i][j]=a[i][j];
									    				}
									    			}
									    		}
										    	flag=1;
										    	for(int i=1;i<=6;i++)
										    	{
										    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
													continue;
													else
													{
														flag=0;
														break;
													}
										    	}
										    	if(flag==1)
										    	cout<<"YES"<<endl;
										    	else
										    	{
													for(int i=1;i<=6;i++)//11
										    		{
										    			for(int j=1;j<=4;j++)
										    			{
										    				if(i==1||i==3)
										    				{
										    					b[i][j]=a[i][j];
										    				}
										    				else if(i==5)
										    				{
										    					if(j==1)
										    					b[i][j]=a[i][j];
										    					else if(j==2)
										    					b[i][j]=a[2][1];
										    					else if(j==3)
										    					b[i][j]=a[i][j];
										    					else if(j==4)
										    					b[i][j]=a[2][2];
										    				}
										    				else if(i==4)
										    				{
										    					if(j==1)
										    					b[i][j]=a[i][j];
										    					else if(j==2)
										    					b[i][j]=a[i][j];
										    					else if(j==3)
										    					b[i][j]=a[5][4];
										    					else if(j==4)
										    					b[i][j]=a[5][2];
										    				}
										    				else if(i==6)
										    				{
										    					if(j==1)
										    					b[i][j]=a[4][3];
										    					else if(j==2)
										    					b[i][j]=a[i][j];
										    					else if(j==3)
										    					b[i][j]=a[4][4];
										    					else if(j==4)
										    					b[i][j]=a[i][j];
										    				}
										    				else if(i==2)
										    				{
										    					if(j==1)
										    					b[i][j]=a[6][3];
										    					else if(j==2)
										    					b[i][j]=a[6][1];
										    					else if(j==3)
										    					b[i][j]=a[i][j];
										    					else if(j==4)
										    					b[i][j]=a[i][j];
										    				}
										    			}
										    		}
											    	flag=1;
											    	for(int i=1;i<=6;i++)
											    	{
											    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
														continue;
														else
														{
															flag=0;
															break;
														}
											    	}
											    	if(flag==1)
											    	cout<<"YES"<<endl;
											    	else
											    	{
													    for(int i=1;i<=6;i++)//12
											    		{
											    			for(int j=1;j<=4;j++)
											    			{
											    				if(i==1||i==3)
											    				{
											    					b[i][j]=a[i][j];
											    				}
											    				else if(i==5)
											    				{
											    					if(j==1)
											    					b[i][j]=a[2][3];
											    					else if(j==2)
											    					b[i][j]=a[i][j];
											    					else if(j==3)
											    					b[i][j]=a[2][4];
											    					else if(j==4)
											    					b[i][j]=a[i][j];
											    				}
											    				else if(i==4)
											    				{
											    					if(j==1)
											    					b[i][j]=a[5][3];
											    					else if(j==2)
											    					b[i][j]=a[5][1];
											    					else if(j==3)
											    					b[i][j]=a[i][j];
											    					else if(j==4)
											    					b[i][j]=a[i][j];
											    				}
											    				else if(i==6)
											    				{
											    					if(j==1)
											    					b[i][j]=a[i][j];
											    					else if(j==2)
											    					b[i][j]=a[4][1];
											    					else if(j==3)
											    					b[i][j]=a[i][j];
											    					else if(j==4)
											    					b[i][j]=a[4][2];
											    				}
											    				else if(i==2)
											    				{
											    					if(j==1)
											    					b[i][j]=a[i][j];
											    					else if(j==2)
											    					b[i][j]=a[i][j];
											    					else if(j==3)
											    					b[i][j]=a[6][4];
											    					else if(j==4)
											    					b[i][j]=a[6][2];
											    				}
											    			}
											    		}
												    	flag=1;
												    	for(int i=1;i<=6;i++)
												    	{
												    		if(b[i][1]==b[i][2]&&b[i][2]==b[i][3]&&b[i][3]==b[i][4])
															continue;
															else
															{
																flag=0;
																break;
															}
												    	}
												    	if(flag==1)
												    	cout<<"YES"<<endl;
												    	else
												    	{
												    		cout<<"NO"<<endl;
												    	}
											    	}
										    	}
									    	}
								    	}
							    	}
						    	}
					    	}
				    	}
			    	}
		    	}
	    	}
    	}
    }
    return 0;
}

 

全部评论

相关推荐

头像 会员标识
12-16 14:43
浙江大学 Java
投递牛客等公司6个岗位
点赞 评论 收藏
分享
12-04 15:13
点赞 评论 收藏
分享
12-14 11:43
黑龙江大学 Java
用微笑面对困难:确实比较烂,可以这么修改:加上大学的qs排名,然后大学简介要写一些,然后硕士大学加大加粗,科研经历第一句话都写上在复旦大学时,主要负责xxxx,简历左上角把学校logo写上,建议用复旦大学的简历模板
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务