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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

DFS 之 poj 2386 Lake Counting

發布時間:2025/4/14 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DFS 之 poj 2386 Lake Counting 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//??[11/1/2014?JmingS] /* 遍歷整個圖,找到?'W'?的點,對其周圍八個點其進行深搜,若是?'W'?則用?'.'?替換。 最后,在遍歷整個圖的過程中,找到多少個?'W',即答案。。。 */
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <cmath> 5 #include <algorithm> 6 #include <functional> 7 #include <string> 8 #include <cstring> 9 #include <vector> 10 #include <stack> 11 #include <queue> 12 #include <map> 13 using namespace std; 14 #define eps 1e-8 15 #define MAX 105 16 17 int N, M; 18 char Graph[MAX][MAX]; 19 const int direction[8][2] = { { -1, 1 }, { 0, 1 }, { 1, 1 }, { -1, 0 }, { 1, 0 }, { -1, -1 }, { 0, -1 }, { 1, -1 } }; 20 21 void Dfs(int x, int y) { 22 Graph[x][y] = '.'; 23 for (int i = 0; i < 8; ++i) { 24 int tx = x + direction[i][0], ty = y + direction[i][1]; 25 if ((tx >= 0) && (tx < N) && (ty >= 0) && (ty < M) && ('W' == Graph[tx][ty])) { 26 Dfs(tx, ty); 27 } 28 } 29 return; 30 } 31 32 void Solve() { 33 int Sum = 0; 34 for (int i = 0; i < N; ++i) { 35 for (int j = 0; j < M; ++j) { 36 if ('W' == Graph[i][j]) { 37 Dfs(i, j); 38 //cout << i << " " << j << endl; 39 ++Sum; 40 } 41 } 42 } 43 printf("%d\n", Sum); 44 } 45 46 int main() 47 { 48 //freopen("input.txt", "r", stdin); 49 scanf("%d %d", &N, &M); 50 for (int i = 0; i < N; ++i) { 51 getchar(); 52 for (int j = 0; j < M; ++j) { 53 scanf("%c", &Graph[i][j]); 54 } 55 } 56 Solve(); 57 return 0; 58 }

轉載于:https://www.cnblogs.com/shijianming/p/4140795.html

總結

以上是生活随笔為你收集整理的DFS 之 poj 2386 Lake Counting的全部內容,希望文章能夠幫你解決所遇到的問題。

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