Example #1
0
int main() {
    ifstream in("/home/joshua/Downloads/s4.4.in");
    while(1) {
        done=0;
        int N;
        in>>N;
        if(!N) break;
        for(int i=0;i<32609;i++) MHASH[i].clear();
        _.clear();
        m.clear();
        int X;
        for(int i=0;i<N;i++) {
            place p,v;
            in>>X;
            p.push_back(X);
            _.push_back(p);
            v.push_back(i+1);
            m.push_back(v);
        }
        superhash=hash(m);
        recurse(_,0);
        while(Q.size()) {
            state l=Q.front().first;
            int m=Q.front().second;
            Q.pop_front();
            recurse(l,m);
        }
        bool ok=0;
        for(set<gstate>::iterator it=MHASH[superhash].begin();it!=MHASH[superhash].end();++it) {
            if((*it).first==m) { ok=1; cout<< ((*it).second)<<endl; break; }
        }
        if(!ok) cout<<"IMPOSSIBLE"<<endl;
    }
}