基本的dfs的题,看了挑战程序设计这本书对这个算法有了些初步的了解,通过不断的查找不断的更改,找到连在一起的块,提交poj的时候compile error 了两次,第一次没有修改编译器,可能是很久没做题的原因了吧,然后就是纠结是否输入的时候要加循环,导致while 的括号多了一个,我的codeblocks也没发现这个bug,算了,acm的题还是多练吧
#include
#include
us...
分类:
其他好文 时间:
2014-10-12 20:19:48
阅读次数:
201
从任意的W开始,不停地把邻接的部分用'.'代替。1次DFS后与初始的这个W连接的所有W就都被替换成了'.',因此直到图中不再存在W为止,总共进行DFS的次数就是答案了。8个方向共对应了8种状态转移,每个格子作为DFS的参数至多被调用一次,所以复杂度为O(8×N×M)=O(N×M)。
#include
#include
#include
#include
using namespace std;
...
分类:
其他好文 时间:
2014-09-30 00:32:41
阅读次数:
215
有一个大小为N*M的园子,雨后积水。八连通的积水被认为是连接在一起的,求出园子里共有多少水洼(八连通是下图中相对W的*部分)。* * **W** * *分析:从任意的W开始,不停地把邻接的部分用'.'代替。1次dfs后与初始的W连接的所有的W都被替换成'.',即这个水洼消失了。因此直到图中不存在W为...
分类:
其他好文 时间:
2014-09-27 13:55:19
阅读次数:
400
最简单的DFS
Lake Counting
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 20516
Accepted: 10338
Description
Due to recent rains, water has pooled in various pla...
分类:
其他好文 时间:
2014-09-20 10:08:07
阅读次数:
259
FroggerTime Limit:1000MSMemory Limit:65536KTotal Submissions:26226Accepted:8538DescriptionFreddy Frog is sitting on a stone in the middle of a lake. S...
分类:
其他好文 时间:
2014-09-11 17:04:32
阅读次数:
228
Description
The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, ha...
分类:
其他好文 时间:
2014-08-23 17:46:51
阅读次数:
304
All the things present from the universe is frequently modifying each of the time regardless of irrespective of whether it has occurred in past times ...
分类:
其他好文 时间:
2014-08-22 12:36:36
阅读次数:
219
Calcium powder(Heavy Gaifenpowder) applies to be fillers for various products, for example artificial stone, artificial floor tiles, organic rubber, s...
分类:
其他好文 时间:
2014-08-20 12:24:32
阅读次数:
199
Artificial Intelligence - Wiley - Data Mining - Concepts Models Methods and Algorithms - 2003.chm8.4 MBIEEE - Finding Patterns in Three Dimensional Gr...
分类:
其他好文 时间:
2014-08-16 22:24:51
阅读次数:
286
简单的深度搜索就可以了,看见有人说什么使用并查集,那简直是大算法小用了。
因为可以深搜而不用回溯,故此效率就是O(N*M)了。
技巧就是增加一个标志P,每次搜索到池塘,即有W字母,那么就认为搜索到一个池塘了,P值为真。
搜索过的池塘不要重复搜索,故此,每次走过的池塘都改成其他字母,如'@',或者'#',随便一个都可以。
然后8个方向搜索。
#include
#include
#inc...
分类:
其他好文 时间:
2014-08-15 23:51:10
阅读次数:
519