D. Blocks time limit 1000 MS memory limit 65536 kb title
Given N? M In the left-side Navigation Pane. How many rectangles are composed of '#'? "There are 5 ships." If there is a Unicom block that is not a rectangle, the output is "so sad"
Input Format
1 ≤ n, m ≤ 1000
Multiple groups of data exist, and EOF ends.
Output Format
Each row corresponds to an answer.
Input example
6 8.....#.###.....###.....#.......##......##..#...#6 8.....#.###.....####...##.......###.....##..#...#
Output example
There are 5 ships.So Sad
Link: http://code.bupt.edu.cn/problem/p/407/
Check whether there are invalid rectangles. If not, the number of rectangles is output,
The stupid method is to use a struct to store the coordinates of the top left and bottom right vertices of a rectangle, traverse the matrix on one side, and start processing when "#" is encountered, record the coordinates (x, y) of the vertex at this time as the starting point of the rectangle, and then look for "#" in this line. If ". "Stop, and record the current y value (Y1) as the coordinates of the end point, and then from the coordinates (x + 1, Y) start processing. If there is "#" and ". the matrix is invalid. Otherwise, the scan continues until the next row is full. ". Next, check whether "#" exists in the line before the start and end points of each row. If yes, it is invalid. Each time you process a "#", you must set it to "." To prevent the next scan to this point.
A more skillful method is as follows: if this rectangle is illegal, there must be one of the four conditions: Yes, yes, and yes, it is invalid. If it does not exist, the number of rectangles in the number is also skillful. as long as such a structure exists, there must be a rectangle, you only need to count the number of rectangles.
Students talk about the method as follows: they also use struct to store struct information, and then record the maximum length and maximum width of each connected block. If the area of the connected block is equal to the maximum length * the maximum width, A rectangle exists. Otherwise, the rectangle jumps out. It is also relatively simple.
The AC code of the first method: