代码丑陋到不行,不过我ACACACACACACAC了啊哈哈哈哈哈哈
有空会来改的
#include<stdio.h>
#define INFINITY 2000000000
typedef struct{
int i;
int j;}po;
main(){
int n,m;
char map[100][100];
int betime[100][100];
int plus;
int flag;
int i,j;
int min;
po mpo[100];
int cpo;
while(scanf("%d %d",&n,&m)!=EOF){
for(i=0;i<n;i++) scanf("%s",map[i]);
for(i=0;i<n;i++) for(j=0;j<m;j++) betime[i][j]=INFINITY;
betime[0][0]=0;
do{
flag=0;
for(i=0;i<n;i++) for(j=0;j<m;j++) {
if(map[i][j]=='X') continue;
if(map[i][j]=='.') plus=1;
else plus=map[i][j]-47;
if(j+1<m&&betime[i][j+1]+plus<betime[i][j]) {betime[i][j]=betime[i][j+1]+plus;flag=1;}
if(i+1<n&&betime[i+1][j]+plus<betime[i][j]) {betime[i][j]=betime[i+1][j]+plus;flag=1;}
if(j-1>=0) if(betime[i][j-1]+plus<betime[i][j]) {betime[i][j]=betime[i][j-1]+plus;flag=1;}
if(i-1>=0) if(betime[i-1][j]+plus<betime[i][j]) {betime[i][j]=betime[i-1][j]+plus;flag=1;}
}
}while(flag);
if(betime[n-1][m-1]==INFINITY) printf("God please help our poor hero.\nFINISH\n");
else{
printf("It takes %d seconds to reach the target position, let me show you the way.\n",betime[n-1][m-1]);
mpo[0].i=n-1;mpo[0].j=m-1;cpo=0;
while(mpo[cpo].i!=0||mpo[cpo].j!=0){
i=mpo[cpo].i;j=mpo[cpo].j;
min=INFINITY;
if(i+1<n&&betime[i+1][j]<min) {min=betime[i+1][j];mpo[cpo+1].i=i+1;mpo[cpo+1].j=j;}
if(i-1>=0&&betime[i-1][j]<min) {min=betime[i-1][j];mpo[cpo+1].i=i-1;mpo[cpo+1].j=j;}
if(j+1<m&&betime[i][j+1]<min) {min=betime[i][j+1];mpo[cpo+1].i=i;mpo[cpo+1].j=j+1;}
if(j-1>=0&&betime[i][j-1]<min) {min=betime[i][j-1];mpo[cpo+1].i=i;mpo[cpo+1].j=j-1;}
cpo++;
}
i=1;
for(cpo;cpo>0;cpo--) {
if(map[mpo[cpo].i][mpo[cpo].j]=='.'){
printf("%ds:(%d,%d)->(%d,%d)\n",i,mpo[cpo].i,mpo[cpo].j,mpo[cpo-1].i,mpo[cpo-1].j);
i++;}else{
plus=map[mpo[cpo].i][mpo[cpo].j]-47;
for(plus;plus>1;plus--) {printf("%ds:FIGHT AT (%d,%d)\n",i,mpo[cpo].i,mpo[cpo].j);i++;}
printf("%ds:(%d,%d)->(%d,%d)\n",i,mpo[cpo].i,mpo[cpo].j,mpo[cpo-1].i,mpo[cpo-1].j);
i++;
}}
if(map[n-1][m-1]!='.'){
plus=map[n-1][m-1]-47;
for(plus;plus>1;plus--) {printf("%ds:FIGHT AT (%d,%d)\n",i,mpo[0].i,mpo[0].j);i++;}}
printf("FINISH\n");
}
}}