ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1016. Cube on the Walk

WA8???
Posted by RAVEman 23 Mar 2007 22:12
Where is my mistake???

#include<stdio.h>
#include<stdlib.h>
#include<fstream>
#include<iostream>
#include<string.h>
#include<vector>
#include<queue>
#include<math.h>

using namespace std;

int m[10][10][40];
char s1[5],s2[5];
int vals[10];

struct Point{
    int a,b;

    Point(char *s){
        b=s[0]-'a';
        a=s[1]-'1';
    }

    Point(int p1,int p2){
        a=p1;
        b=p2;
    }

    char* GetPos(){
        char *s=new char[4];
        s[0]='a'+b;
        s[1]='1'+a;
        s[2]='\x0';
        return s;
    }

    bool Valid(){
        if(a>=0 && a<8)
            if(b>=0 && b<8)
                return true;
        return false;
    }



    Point(){
    }
};

struct Cube{
    int r[6];

    int GetHashCode(){
        return r[0]*6+r[1];
    }

    void Rotate(int d){
        if(d==0){
            swap(r[0],r[4]);
            swap(r[2],r[0]);
            swap(r[1],r[2]);
            //swap(r[4],r[1]);
        }else if(d==2){
            swap(r[0],r[2]);
            swap(r[4],r[0]);
            swap(r[1],r[4]);
    //        swap(r[2],r[1]);
        }else if(d==1){
            swap(r[2],r[3]);
            swap(r[5],r[2]);
            swap(r[4],r[5]);
      //      swap(r[3],r[4]);
        }else{
            swap(r[3],r[2]);
            swap(r[4],r[3]);
            swap(r[5],r[4]);
            //swap(r[2],r[5]);
        }
    }
};
// 0 - forward
// 1 - backward
// 2 - top
// 3 - right
// 4 - bottom
// 5 - left

struct Position{
    Cube c;
    Point p;
    int curr_sum;
    int from;

    bool Update(){
        curr_sum+=vals[c.r[4]];
        if(m[p.a][p.b][c.GetHashCode()]>curr_sum){
            m[p.a][p.b][c.GetHashCode()]=curr_sum;
            return true;
        }
        return false;
    }

    Position(){
    }

    Position(Point x,Cube y,int sum){
        p=x;
        c=y;
        curr_sum=sum;
    }
};



int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

vector<Position> mas;
int head=0;
int tail=1;

void rec(Position e){
    if(!(e.p.a==Point(s1).a && e.p.b==Point(s1).b && e.c.GetHashCode()==1))
        rec(mas[e.from]);

    cout<<" "<<e.p.GetPos();
}

int main(){
    for(int i=0;i<=8;i++)
        for(int j=0;j<=8;j++)
            for(int k=0;k<=36;k++)
                m[i][j][k]=1000000000;

    cin>>s1>>s2;
    Position p;
    p.p=Point(s1);
    for(int i=0;i<6;i++){
        cin>>vals[i];
        p.c.r[i]=i;
    }

    p.curr_sum=0;
    p.Update();

    mas.push_back(p);


    int mn=1000000,pos=0;
    Point end(s2);

    while(head<tail){
        Position p=mas[head];

        if(p.p.a==end.a && p.p.b==end.b)
            if(mn>p.curr_sum){
                mn=p.curr_sum;
                pos=head;
            }

        for(int i=0;i<4;i++)
        {
            Point nw(p.p.a+dx[i],p.p.b+dy[i]);
            if(nw.Valid()){
                Position _n(nw,p.c,p.curr_sum);
                _n.c.Rotate(i);
                _n.from=head;

                if(_n.Update()){
                    mas.push_back(_n);
                    tail++;
                }
            }
        }
        head++;
    }

    Position e=mas[pos];
    cout<<m[e.p.a][e.p.b][e.c.GetHashCode()];
    rec(e);
    cout<<endl;

    system("pause");
    return 0;
}


i get wa8.

Thanks for help!!!
Re: WA8???
Posted by zinccopper 3 Dec 2007 17:03
Try the input data below:
 a1 h8 1000 0 0 0 1000 0
My program's output is:
 1000 a1 b1 b2 b3 c3 c2 d2 d3 c3 c4 d4 d3 e3 e4 d4 d5 e5 e4 f4  f5 e5 e6 f6 f5 g5 g6 f6 f7 g7 g6 h6 h7 h8