多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > POJ2386 Lake Counting 【DFS】

POJ2386 Lake Counting 【DFS】

來源:程序員人生   發布時間:2014-11-14 08:23:31 閱讀次數:2343次

Lake Counting
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 20782   Accepted: 10473

Description

Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John would like to figure out how many ponds have formed in his field. A pond is a connected set of squares with water in them, where a square is considered adjacent to all eight of its neighbors. 

Given a diagram of Farmer John's field, determine how many ponds he has.

Input

* Line 1: Two space-separated integers: N and M 

* Lines 2..N+1: M characters per line representing one row of Farmer John's field. Each character is either 'W' or '.'. The characters do not have spaces between them.

Output

* Line 1: The number of ponds in Farmer John's field.

Sample Input

10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W.

Sample Output

3

Hint

OUTPUT DETAILS: 

There are three ponds: one in the upper left, one in the lower left,and one along the right side.

Source

USACO 2004 November

睡前水1水。

#include <stdio.h> #include <string.h> #define maxn 102 char G[maxn][maxn]; int n, m; const int mov[][2] = {0, 1, 0, ⑴, 1, 0, ⑴, 0, 1, ⑴, ⑴, 1, 1, 1, ⑴, ⑴}; void DFS(int x, int y) { G[x][y] = '.'; int i, j, nx, ny; for(i = 0; i < 8; ++i) { nx = x + mov[i][0]; ny = y + mov[i][1]; if(nx >= 0 && nx < n && ny >= 0 && ny < m && G[nx][ny] == 'W') DFS(nx, ny); } } int main() { int i, j, ret; while(scanf("%d%d", &n, &m) == 2) { for(i = 0; i < n; ++i) scanf("%s", G[i]); ret = 0; for(i = 0; i < n; ++i) for(j = 0; j < m; ++j) if(G[i][j] == 'W') { DFS(i, j); ++ret; } printf("%d ", ret); } return 0; }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 图片区小说区av区 | 亚洲精品视频在线看 | 18videosex性欧美68 | 免费看片亚洲 | 一区二区三区高清不卡 | 欧美大屁股精品毛片视频 | 国产乱码精品一区二区三区四川 | 亚洲欧美综合国产精品一区 | 老司机精品视频午夜免费视频 | 欧美成人久久久免费播放 | jizz亚洲视频 | 在线看福利片 | 福利视频一二区 | 国产亚洲福利精品一区二区 | 国产精品福利在线观看 | 亚洲一区 中文字幕 久久 | 国产精品欧美日韩一区二区 | 亚洲日比视频 | 在线高清美女视频免费看 | 亚洲一区二区三区高清 | 日本理论免费高清在线视频 | 亚洲精品久久久久中文 | 国产一级一级一级成人毛片 | 综合久久久久 | 黄色免费网站网址 | 亚洲国产人成在线观看 | 久久天天躁夜夜躁狠狠85台湾 | 亚洲精品欧美 | 日本人与物videos另类 | 欧美极品video粗暴 | 色综合亚洲精品激情狠狠 | 国产尤物在线播放 | 亚洲日韩精品欧美一区二区 | 在线观看免费a∨网站 | 最新亚洲一区二区三区四区 | 黄色在线观看www | 亚洲一区二区三区高清 不卡 | 亚洲欧美日韩精品久久亚洲区 | 中国xxxx做受欧美1314 | 性欧美videofree另类17 | 精品视频一区二区三三区四区 |