~~~~
题意: 给你一个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/problem?id=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