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!!!