Pocket Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 11 Accepted Submission(s): 7
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.
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.
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.
問能否還原二階魔方,保持顏色對面。
方法:通過8個角,每個角三個顏色。暴力驗證,wa了。
待續更新。。。。。
#include<iostream>
#include<cstdio>
#include<set>
#include<string>
#include<cstring>
using namespace std;
char mapt[100][220];
int mark[100][220];
set < string > st;
set < string > rt;
void findxy(int &x,int &y,char ch){
for(int i=0;i<8;i++)
for(int j=0;j<6;j++)
if(mark[i][j]==0&&mapt[i][j]==ch){
x=i;
y=j;
mark[i][j]=1;
return ;
}
}
int main(){
int CAS;scanf("%d",&CAS);
for(int CA = 1;CA<=CAS;CA++){
memset(mark,0,sizeof mark);
st.clear();
rt.clear();
char str[100]; gets(str);
for(int i=0;i<8;i++){
gets(str);
int len=strlen(str);
int t=0;
for(int j=0;j<len;j+=2)
mapt[i][t++]=str[j];
mapt[i][t]='\0';
}
for(int i=0;i<2;i++){
for(int j=0;j<4;j++){
char ch;
if(i==0)ch='w';
else ch='y';
int x,y; findxy(x,y,ch);
string s="";
if(x==0&&y==2){s=s+mapt[2][0]+ch+mapt[7][2];st.insert(s);rt.insert(s);}
if(x==0&&y==3){s=s+mapt[7][3]+ch+mapt[2][5];st.insert(s);rt.insert(s);}
if(x==1&&y==2){s=s+mapt[2][2]+ch+mapt[2][1];st.insert(s);rt.insert(s);}
if(x==1&&y==3){s=s+mapt[2][4]+ch+mapt[2][3];st.insert(s);rt.insert(s);}
if(x==2&&y==0){s=s+mapt[7][2]+ch+mapt[0][2];st.insert(s);rt.insert(s);}
if(x==2&&y==1){s=s+mapt[1][2]+ch+mapt[2][2];st.insert(s);rt.insert(s);}
if(x==2&&y==2){s=s+mapt[2][1]+ch+mapt[1][2];st.insert(s);rt.insert(s);}
if(x==2&&y==3){s=s+mapt[1][3]+ch+mapt[2][4];st.insert(s);rt.insert(s);}
if(x==2&&y==4){s=s+mapt[2][3]+ch+mapt[1][3];st.insert(s);rt.insert(s);}
if(x==2&&y==5){s=s+mapt[0][3]+ch+mapt[7][3];st.insert(s);rt.insert(s);}
if(x==3&&y==0){s=s+mapt[5][2]+ch+mapt[6][2];st.insert(s);rt.insert(s);}
if(x==3&&y==1){s=s+mapt[3][2]+ch+mapt[4][2];st.insert(s);rt.insert(s);}
if(x==3&&y==2){s=s+mapt[4][2]+ch+mapt[3][1];st.insert(s);rt.insert(s);}
if(x==3&&y==3){s=s+mapt[3][4]+ch+mapt[4][3];st.insert(s);rt.insert(s);}
if(x==3&&y==4){s=s+mapt[4][3]+ch+mapt[3][3];st.insert(s);rt.insert(s);}
if(x==3&&y==5){s=s+mapt[6][3]+ch+mapt[5][3];st.insert(s);rt.insert(s);}
if(x==4&&y==2){s=s+mapt[3][1]+ch+mapt[3][2];st.insert(s);rt.insert(s);}
if(x==4&&y==3){s=s+mapt[3][3]+ch+mapt[3][4];st.insert(s);rt.insert(s);}
if(x==5&&y==2){s=s+mapt[6][2]+ch+mapt[3][0];st.insert(s);rt.insert(s);}
if(x==5&&y==3){s=s+mapt[3][5]+ch+mapt[6][3];st.insert(s);rt.insert(s);}
if(x==6&&y==2){s=s+mapt[3][0]+ch+mapt[5][2];st.insert(s);rt.insert(s);}
if(x==6&&y==3){s=s+mapt[5][3]+ch+mapt[3][5];st.insert(s);rt.insert(s);}
if(x==7&&y==2){s=s+mapt[0][2]+ch+mapt[2][0];st.insert(s);rt.insert(s);}
if(x==7&&y==3){s=s+mapt[2][5]+ch+mapt[0][3];st.insert(s);rt.insert(s);}
}
}
printf("Case #%d: ",CA);
set<string>::iterator it;
cout<<st.size()<<endl;
for(it=st.begin();it!=st.end();it++)
cout<<*it <<" ";
cout<<endl;
if(st.size()!=8){
puts("NO");
}else{
st.insert("owg");
st.insert("bwo");
st.insert("gwr");
st.insert("rwb");
st.insert("ryg");
st.insert("byr");
st.insert("oyb");
st.insert("gyo");
cout<<st.size()<<endl;
for(it=st.begin();it!=st.end();it++)
cout<<*it <<" ";
cout<<endl;
if(st.size()==8){
puts("YES");
}else{
rt.insert("gwo");
rt.insert("owb");
rt.insert("rwg");
rt.insert("bwr");
rt.insert("gyr");
rt.insert("ryb");
rt.insert("byo");
rt.insert("oyg");
if(rt.size()!=8){
puts("NO");
}else{
puts("YES");
}
}
}
}
return 0;
}