哼 EOF超时了
还有打印的时候坐标反了 哼 wa了两次
哼 我这人真的编译过就过的 就这么任性样例都不测一下的呢
超任性的!
#include#include #include #include using namespace std;struct node{ int x,y,step; friend bool operator < (node n1,node n2){ return n1.step > n2.step; }}cur,cur1,next;const int maxn = 100 + 10;int map[maxn][maxn];int blood[maxn][maxn];int flag[maxn][maxn];int dir[4][2] = { 0,1,1,0,0,-1,-1,0},dr[4][2] = { 0,1,1,0,0,-1,-1,0};;int n,m;int judge_ok(int cx,int cy){ if(cx < 0||cy < 0||cx >= n||cy >= m) return 0; if(map[cx][cy] == -1) return 0; return 1;}int bFS(int x0,int y0){ int i,j,cx,cy; cur.x = x0; cur.y = y0; cur.step = 0; priority_queue q; q.push(cur); map[x0][y0] = -1; while(!q.empty()){ cur = q.top();q.pop(); if(cur.x == n - 1&&cur.y == m - 1) return cur.step; for(i = 0;i < 4;i++){ cur1.x = cur.x + dr[i][0]; cur1.y = cur.y + dr[i][1]; if(judge_ok(cur1.x,cur1.y)){ cur1.step = cur.step + 1 + map[cur1.x][cur1.y]; map[cur1.x][cur1.y] = -1; flag[cur1.x][cur1.y] = i + 1; q.push(cur1); } } } return -1;}int cur_step = 1;void PRINT(int x,int y){ if(flag[x][y] == 0) return; int next_x = x - dr[flag[x][y]-1][0]; int next_y = y - dr[flag[x][y]-1][1]; PRINT(next_x,next_y);//往前走 printf("%ds:(%d,%d)->(%d,%d)\n",cur_step++,next_x,next_y,x,y); while(blood[x][y]--){ printf("%ds:FIGHT AT (%d,%d)\n",cur_step++,x,y); }}int main(){ while(scanf("%d%d",&n,&m) != EOF){ memset(map,0,sizeof(map)); memset(flag,0,sizeof(flag)); memset(blood,0,sizeof(blood)); char s[110];int i,j; for(i = 0;i < n;i++){ scanf("%s",s); for(j = 0;j < m;j++){ if(s[j] == '.') map[i][j] = 0; else if(s[j] == 'X') map[i][j] = -1; else{ map[i][j] = blood[i][j] = s[j] - '0'; } } } int result = bFS(0,0); if(result == -1) printf("God please help our poor hero.\n"); else{ printf("It takes %d seconds to reach the target position, let me show you the way.\n",result); //PRINT(n-1,m-1); cur_step = 1; PRINT(n-1,m-1); } printf("FINISH\n"); } return 0;}