日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj3669 Meteor Shower(预处理+bfs)

發布時間:2024/1/17 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj3669 Meteor Shower(预处理+bfs) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

https://vjudge.net/problem/POJ-3669

先給地圖a[][]預處理每個位置被砸的最小時間。然后再bfs。

純bfs,還被cin卡了下時間。。

1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 #include<stack> 8 #define lson l, m, rt<<1 9 #define rson m+1, r, rt<<1|1 10 #define IO ios::sync_with_stdio(false);cin.tie(0); 11 #define INF 0x3f3f3f3f 12 typedef unsigned long long ll; 13 using namespace std; 14 int a[310][310], vis[310][310]; 15 int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0}; 16 typedef struct{ 17 int a, b; 18 int step; 19 }Node; 20 Node node; 21 void bfs() 22 { 23 queue<Node> q; 24 node.a = 0; node.b = 0; 25 node.step = 0; 26 q.push(node); 27 vis[0][0] = 1; 28 while(!q.empty()){ 29 Node t = q.front(), p; 30 if(a[t.a][t.b] == INF){ 31 cout << t.step << endl; 32 break; 33 } 34 for(int i = 0; i < 4; i++){ 35 int tx = t.a + dir[i][0]; 36 int ty = t.b + dir[i][1]; 37 if(tx>=0&&ty>=0&&!vis[tx][ty]){ 38 if(t.step+1<a[tx][ty]){ 39 p.a = tx; p.b = ty; 40 p.step = t.step+1; 41 vis[tx][ty] = 1; 42 q.push(p); 43 } 44 } 45 } 46 q.pop(); 47 } 48 if(q.empty()){ 49 cout << "-1" << endl; 50 } 51 } 52 int main() 53 { 54 IO; 55 int m, x, y, t; 56 memset(vis, 0, sizeof(vis)); 57 for(int i = 0; i < 310; i++){ 58 for(int j = 0; j < 310; j++){ 59 a[i][j] = INF; 60 } 61 } 62 cin >> m; 63 for(int i = 0; i < m; i++){ 64 cin >> x >> y >> t; 65 a[x][y] = min(a[x][y], t); 66 for(int j = 0; j < 4; j++){ 67 int tx = x + dir[j][0]; 68 int ty = y + dir[j][1]; 69 if(tx>=0&&ty>=0){ 70 a[tx][ty] = min(a[tx][ty], t); 71 } 72 } 73 } 74 /*for(int i = 0; i < 10; i++){ 75 for(int j = 0; j < 10; j++){ 76 cout << a[i][j] << " " ; 77 } 78 cout << endl; 79 }*/ 80 bfs(); 81 return 0; 82 }

?

轉載于:https://www.cnblogs.com/Surprisezang/p/8991555.html

總結

以上是生活随笔為你收集整理的poj3669 Meteor Shower(预处理+bfs)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。