2015 Multi-University Training Contest 1 Hdu 5292 Pocket Cube

Pocket Cube

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


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)

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. 
 

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
 

問能否還原二階魔方,保持顏色對面。

方法:通過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;
}



發佈了138 篇原創文章 · 獲贊 1 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章