设为首页 加入收藏

TOP

POJ 2386 Lake Counting 搜索题解
2015-07-20 17:54:34 来源: 作者: 【 】 浏览:1
Tags:POJ 2386 Lake Counting 搜索 题解

简单的深度搜索就可以了,看见有人说什么使用并查集,那简直是大算法小用了。

因为可以深搜而不用回溯,故此效率就是O(N*M)了。

技巧就是增加一个标志P,每次搜索到池塘,即有W字母,那么就认为搜索到一个池塘了,P值为真。

搜索过的池塘不要重复搜索,故此,每次走过的池塘都改成其他字母,如'@',或者'#',随便一个都可以。

然后8个方向搜索。

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             #include 
             using namespace std; const int MAX_N = 101; char pond[MAX_N][MAX_N]; const char VIS = '@'; int N, M; bool P; inline bool isLegal(int r, int c) { return 0<=r && 0<=c && r
             
              


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ3311 Hie with the Pie 状压DP 下一篇POJ 1379 模拟退火算法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: