~~~~
題意: 給你一個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