题目思想比較简单,可是题目要求输出路径比較麻烦,学习了 博主的方法,感觉不错。
#include#include"stdio.h"#include"string.h"#include"queue"using namespace std;const int maxn = 100 + 5;struct node{ int x,y; int step; friend bool operator<(node n1,node n2) { return n1.step>n2.step; }};int dir[4][2]={0,1,1,0,0,-1,-1,0};int map[maxn][maxn];int flag[maxn][maxn];int blood[maxn][maxn];int n,m;int ptime;int BFS(){ priority_queue Q; node s; s.x = 0; s.y = 0; s.step = 0; map[0][0] = -1; Q.push(s); while(!Q.empty()) { if(Q.top().x==n-1 && Q.top().y==m-1) return Q.top().step; node next; for(int i=0;i<4;i++) { next.x = Q.top().x + dir[i][0]; next.y = Q.top().y + dir[i][1]; if(next.x>=0 && next.x =0 && next.y (%d,%d)\n",ptime++,nx_x,nx_y,x,y); while(blood[x][y]--) printf("%ds:FIGHT AT (%d,%d)\n",ptime++,x,y);}int main(){ char str[maxn]; int ans; while(scanf("%d%d",&n,&m)!=EOF) { memset(map,0,sizeof(map)); memset(flag,0,sizeof(flag)); memset(blood,0,sizeof(blood)); for(int i=0;i