http://ybt.ssoier.cn:8088/problem_show.php?pid=1255
只对了#3,5,6,各位大神麻烦看看
#include<iostream>
#include<queue>
struct Node{
int x,y,index;
int go[50][50];
};
int direction[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int main(){
int map[10][10];
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
std::cin>>map[i][j];
}
}
int startX=0,startY=0;
int endX=4,endY=4;
std::queue<Node>q;
Node s;
s.x=startX,s.y=startY;
s.go[0][0]=0,s.go[0][1]=0;s.index=1;
q.push(s);
while(!q.empty()){
if(q.front().x==endX&&q.front().y==endY){
for(int i=0;i<q.front().index;i++){
std::cout<<"("<<q.front().go[i][0]<<", "<<q.front().go[i][1]<<")"<<std::endl;
}
break;
}
for(int j=0;j<4;j++){
int nextX=q.front().x+direction[j][0];
int nextY=q.front().y+direction[j][1];
if(nextX>=0&&nextY>=0&&nextX<5&&nextY<5&&map[nextX][nextY]==0){
Node nextNode;
nextNode.x=nextX;
nextNode.y=nextY;
nextNode.index=q.front().index;
for(int i=0;i<q.front().index;i++){
nextNode.go[j][0]=q.front().go[j][0];
nextNode.go[j][1]=q.front().go[j][1];
}
nextNode.go[nextNode.index][0]=nextX;
nextNode.go[nextNode.index][1]=nextY;
nextNode.index++;
map[nextX][nextY]=1;
q.push(nextNode);
}
}
q.pop();
}
}