版本比较
最短路
正文
增加 11 行删除 11 行
41 行未改动4243444546474849504 行未改动5556575859606162637 行未改动71727374757677787956 行未改动1361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671687 行未改动1761771781791801811821831847 行未改动41 行未改动while(!q.empty()){node t=q.front();q.pop();int tx=t.x,ty=t.y,t_st=t.step;int k=1;if(mp[tx][ty]=='A'||mp[tx][ty]=='B'){if(mp[tx][ty]=='B'){k++;4 行未改动vis[nx][ny]=1;if(nx==n&&ny==n){return t_st+1;}q.push({nx,ny,t_st+1,0});}}}else if(mp[tx][ty]=='C'){7 行未改动vis[nx][ny]=1;if(nx==n&&ny==n){return t_st+1;}q.push({nx,ny,t_st+1,0});}}}56 行未改动for(int j = 0; j < m; j++) {dis[i][j] = 1e9;}}priority_queue<node> q;q.push({sx, sy, 0});dis[sx][sy] = 0;while(!q.empty()) {node t = q.top();q.pop();if(t.dis > dis[t.x][t.y]) continue;if(t.x == ex && t.y == ey) {cout << t.dis << endl;return;}for(int i = 0; i < 4; i++) {int nx = t.x + dx[i];int ny = t.y + dy[i];if(!check(nx, ny)) continue;int new_dis = t.dis + 1;if(mp[nx][ny] == 'x') {new_dis = t.dis + 2;}if(new_dis < dis[nx][ny]) {dis[nx][ny] = new_dis;q.push({nx, ny, new_dis});}7 行未改动for(int i = 0; i < n; i++) {for(int j = 0; j < m; j++) {cin >> mp[i][j];if(mp[i][j] == 'a') {ex = i, ey = j;}if(mp[i][j] == 'r') {sx = i, sy = j;}7 行未改动41 行未改动4243444546474849504 行未改动5556575859606162637 行未改动71727374757677787956 行未改动1361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671687 行未改动1761771781791801811821831847 行未改动41 行未改动while(!q.empty()){node t=q.front();q.pop();int tx=t.x,ty=t.y,t_st=t.step;int k=1;if(mp[tx][ty]=='A'||mp[tx][ty]=='B'){if(mp[tx][ty]=='B'){k++;4 行未改动vis[nx][ny]=1;if(nx==n&&ny==n){return t_st+1;}q.push({nx,ny,t_st+1,0});}}}else if(mp[tx][ty]=='C'){7 行未改动vis[nx][ny]=1;if(nx==n&&ny==n){return t_st+1;}q.push({nx,ny,t_st+1,0});}}}56 行未改动for(int j = 0; j < m; j++) {dis[i][j] = 1e9;}}priority_queue<node> q;q.push({sx, sy, 0});dis[sx][sy] = 0;while(!q.empty()) {node t = q.top();q.pop();if(t.dis > dis[t.x][t.y]) continue;if(t.x == ex && t.y == ey) {cout << t.dis << endl;return;}for(int i = 0; i < 4; i++) {int nx = t.x + dx[i];int ny = t.y + dy[i];if(!check(nx, ny)) continue;int new_dis = t.dis + 1;if(mp[nx][ny] == 'x') {new_dis = t.dis + 2;}if(new_dis < dis[nx][ny]) {dis[nx][ny] = new_dis;q.push({nx, ny, new_dis});}7 行未改动for(int i = 0; i < n; i++) {for(int j = 0; j < m; j++) {cin >> mp[i][j];if(mp[i][j] == 'a') {ex = i, ey = j;}if(mp[i][j] == 'r') {sx = i, sy = j;}7 行未改动