poj2386】的更多相关文章

POJ2386 Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25366   Accepted: 12778 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 <=…
2道题目都差不多,就是问和相邻所有点都有相同数据相连的作为一个联通快,问有多少个连通块 因为最近对搜索题目很是畏惧,总是需要看别人代码才能上手,就先拿这两道简单的dfs题目来练练手,顺便理一理dfs的思路,分析清楚dfs的退出递归的条件和什么时候进行递归调用是至关重要的,这两道题目不涉及回溯,对于需要回溯的题目也要清楚分析,找到回溯条件,在对一个新的状态dfs时,后面加上回溯的语句 HDU1241代码: #include <cstdio> #include <cstring> #i…
就是求图中有多少个水洼.对图进行dfs遍历,并把是水洼的地方全部标记.然后从下一个是水哇的地方再进行dfs. #include <cstdio> #include <iostream> #include <cstring> using namespace std; ][]; int sum; ][]; , -, -, , , , , }; , , , -, , -, ,}; int row, col; bool check(int x, int y) { &&a…
Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25322   Accepted: 12759 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 <= 10…
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=1562 --------------------------------------------------------------------------------------------------------------------------------------…
湖计数描述由于最近的降雨,水汇集在不同的地方,在农民约翰的领域,这是代表一个长方形的N×M(1μ= 100:1 = M = 100)平方.每一方都包含水(’w')或干燥的土地(“.”).农民约翰想弄清楚在他的田里已经形成了多少个池塘.一个池塘是一个连接的正方形与水在他们,其中一个正方形被认为是相邻的所有八个它的邻居.给定一个农民约翰的领域的图表,确定他有多少个池塘.输入行1:两个空格分隔的整数:N和M*线2 .. N + 1:M字符每行代表一行的农民约翰的领域.每个字符是“W”或“.”.字符之间…
Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34735   Accepted: 17246 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 <= 10…
Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49414   Accepted: 24273 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 <= 10…
题目链接:http://poj.org/problem?id=2386 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 wa…
本题是一道连通块的入门题,用来练手,后续还会更新连通块的题目. 本题大意:一个n * m 的陆地上面有很多水洼,让你统计水洼的个数并输出. 本题思路:按照顺序遍历陆地,如果发现水洼就将它的八连块都进行探索,发现水洼就继续探索,直到一片大水洼都被探索完,就继续进行其他搜索,DFS. 代码: #include <cstdio> using namespace std; + ; char field[maxn][maxn]; int n, m, ans; void dfs(int u, int v)…