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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

hdu 1241Oil Deposits(BFS)

發布時間:2024/7/19 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 1241Oil Deposits(BFS) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1241

Oil Deposits

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13137????Accepted Submission(s): 7611


Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.

?

Input The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.

?

Output For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.

?

Sample Input 1 1 * 3 5 *@*@* **@** *@*@* 1 8 @@****@* 5 5 ****@ *@@*@ *@**@ @@@*@ @@**@ 0 0

?

Sample Output 0 1 2 2 題目大意: 這個題目就是要查找油田的個數,比如說第二組數據 3 5 *@*@* **@** ? ? ? ? ? ? 注明:"@"這個與他的幾個方向都是@都是可以相連的。所以稱為一塊油田。輸出1。 *@*@* ?這種就很容易想到搜索。這里的一個技巧就是起點就從@開始,其次就是找到@就使其變成*;不過找過的還是要標記為1,否則就會重復,這樣不連接的還可以繼續搜~ 東西還是要反復的咀嚼,不然就會很生,忘得差不多0.0 詳見代碼。 1 #include <iostream> 2 #include <cstdio> 3 #include <queue> 4 #include <cstring> 5 6 using namespace std; 7 8 int dir[8][2]= {0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,1,-1,-1}; 9 char map[110][110]; 10 int a,b,vis[110][110],k; 11 12 struct node 13 { 14 int x,y; 15 int t; 16 } s,ss; 17 18 queue<node>q,qq; 19 int bfs() 20 { 21 while (!q.empty()) 22 { 23 s=q.front(); 24 q.pop(); 25 //vis[s.x][s.y]=1; 26 for (int i=0; i<8; i++) 27 { 28 int x=s.x+dir[i][0]; 29 int y=s.y+dir[i][1]; 30 //int t=s.t+1; 31 if (x>=0&&x<a&&y>=0&&y<b) 32 { 33 if (!vis[x][y]&&map[x][y]=='@') 34 { 35 ss.x=x; 36 ss.y=y; 37 map[ss.x][ss.y]='*'; 38 //vis[x][y]=1; 39 q.push(ss); 40 } 41 42 } 43 } 44 } 45 } 46 47 int main () 48 { 49 while (scanf("%d%d",&a,&b)!=EOF) 50 { 51 memset(vis,0,sizeof(vis)); 52 if (a==0&&b==0) 53 break; 54 for (int i=0; i<a; i++) 55 { 56 getchar(); 57 for (int j=0; j<b; j++) 58 { 59 scanf("%c",&map[i][j]); 60 } 61 } 62 //int k=0; 63 for (int i=k=0; i<a; i++) 64 { 65 for (int j=0; j<b; j++) 66 { 67 if (map[i][j]=='@') 68 { 69 k++; 70 s.x=i; 71 s.y=j; 72 map[s.x][s.y]='*'; 73 vis[s.x][s.y]=1; 74 q.push(s); 75 bfs(); 76 } 77 } 78 } 79 printf ("%d\n",k); 80 } 81 return 0; 82 }

?

轉載于:https://www.cnblogs.com/qq-star/p/4139845.html

總結

以上是生活随笔為你收集整理的hdu 1241Oil Deposits(BFS)的全部內容,希望文章能夠幫你解決所遇到的問題。

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