Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by Tyga ( 17 years ago )
#include <string>
#include <iostream>
#include <map>
#include <vector>
#define FOR(I,A,B) for(int I=(A);I<(B);++I)
using namespace std;
int main(){
        vector<string> a;
        vector<string> b;
        map<string, int> mapa;
        a.push_back("876543210");
        int ruchy=1;

        FOR(i,0,12){
                for(vector<string>::iterator iter=a.begin(); iter != a.end(); iter++){
                        if(mapa[*iter]==0){mapa[*iter]=ruchy;}
                        string tmp=*iter;
                        int j;
                        for(j=0;j<9;j++){
                                if(tmp[j]=='0'){break;}
                        }
                        if(j%3!=2){
                                std::swap(tmp[j],tmp[j+1]);
                                b.push_back(tmp);
                        }
                        if(j%3!=0){
                                tmp=*iter;
                                std::swap(tmp[j],tmp[j-1]);
                                b.push_back(tmp);
                        }
                        if(j<6){
                                tmp=*iter;
                                std::swap(tmp[j],tmp[j+3]);
                                b.push_back(tmp);
                        }
                        if(j>2){
                                tmp=*iter;
                                std::swap(tmp[j],tmp[j-3]);
                                b.push_back(tmp);
                        }
                }
                a=b;
                b.clear();
                ruchy++;
        }
        int t;
        cin>>t;
        while(t--){
                string wejscie, d,e,f;
                cin>>d>>e>>f;
                wejscie=d+e+f;
                cout<<mapa[wejscie]-1<<endl;
        }
return 0;}

 

Revise this Paste

Children: 4807
Your Name: Code Language: