设为首页 加入收藏

TOP

POJ 1856 Sea Battle(BFS).
2015-07-20 17:55:30 】 浏览:7904
Tags:POJ 1856 Sea Battle BFS

~~~~

题意: 给你一个R*C的图,求其由图中连通‘#“所组成的矩形的个数。

注意:If the ships were placed correctly (i.e., there are only rectangles that do not touch each other even with a corner), print the sentence "There are S ships." where S is the number of ships. Otherwise, print the sentence "Bad placement.".

所以若有一组连通的’#‘不能组成矩形,则输出 Bad placement。

题目链接:http://poj.org/problemid=1856

~~~~

思路:对每个’#‘进行DFS,求其’#‘的个数s(就是面积)。DFS同时,记录y可以搜到的最左和最右位置,记录x可以搜到的最上和最下位置。

则若 s==(r-l+1)*(u-d+1),则 tot++..

~~~~

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         #include
        
          #define N 1111 using namespace std; int tot,n,m; int s,l,r,u,d; char g[N][N]; bool ok(int x,int y) { return (x>=0 && x
         
          =0 && y
          
           

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇HDU 4939 Stupid Tower Defense(d.. 下一篇POJ 1856 Sea Battle(dfs)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目