Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18826 Accepted: 9463
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.Input
* Line 1: Two space-separated integers: N and MOutput
* 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:Source
USACO 2004 November#includechar map[101][101]; int n,m; int move[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};//這裡定義八個可行方向 void dfs(int x,int y) { map[x][y]='.'; //標記走過的路徑 for(int i=0;i<8;i++) { int dx=x+move[i][0]; int dy=y+move[i][1]; if(dx>=0&&dx =0&&dy =0&&nx =0&&ny 這個題目讓我也意識到了以前沒有注意到的小細節,以後做題的時候就不能再犯了 ,對於連續字符串的輸入的時候要特別注意,是不是把換行符加入進去了,改變了原字符串的結構,對於連續子都串的輸入要特別注意!!!
下面這道題和上面這道題基本類似,就果斷水過啦~ poj1562
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11971 Accepted: 6474Description
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 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
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 0Sample Output
0 1 2 2Source
Mid-Central USA 1997
下面是我的代碼#include#include char map[102][102]; int move[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}}; int n,m; void dfs(int x,int y) { map[x][y]='*'; for(int i=0;i<8;i++) { int dx=x+move[i][0]; int dy=y+move[i][1]; if(dx>=0&&dx =0&&dy dfs的基礎題水過。