Time limit: 1000MS memory limit: 65535K
Number of submissions: 0 Number of Passes: 0
Question types: programming language: g++; Gcc
Description
You is given a m*m cloth with some holes on it. Your task is to find a biggest square cloth from it. The following is an example (m=5)
Input format
The first line contains the one integer number M (1<= m<=1,000). Then M lines is following. Each line contains M charactors which "." means cloth and "H" means hole.
Output format
The only line of the output contains area of the biggest square cloth mentioned above.
Input sample
5H ... H........... HHH ...
Output sample
9
Author
Admin
Idea: Compare the classic model, there are almost the same original problem on the white
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intN =1005;CharMap[n][n];intUp[n][n], left[n][n], right[n][n];intN;voidGetl () { for(inti =1; I <= N; ++i) {intLo =0; for(intj =1; J <= N; ++j) {if(Map[i][j] = ='.') {Up[i][j]= Up[i-1][J] +1; LEFT[I][J]= Max (Left[i-1][J], lo +1); }Else{Up[i][j]= Left[i][j] =0; Lo=J; } } }}intAns =0;voidGetr () { for(inti =1; I <= N; ++i) {intRO = n +1; for(intj = N; J >=1; --j) {if(Map[i][j] = ='.') {Right[i][j]= Min (Right[i-1][J], Ro-1); }Else{Right[i][j]=N; Ro=J; } ans= Max (ans, min (up[i][j], right[i][j]-left[i][j] +1)); } }}voidShowintA[][n]) { for(inti =1; I <= N; ++i) { for(intj =1; J <= N; ++J) printf ("%d", A[i][j]); Puts (""); }}intMain () { while(~SCANF ("%d", &N)) { for(inti =1; I <= N; ++i) scanf ("%s", Map[i] +1); for(inti =0; I <= N; ++i) up[0][i] =0; for(inti =0; I <= N; ++i) left[0][i] =0; for(inti =0; I <= N; ++i) right[0][i] =N; Getl (); Getr (); printf ("%d\n", ans *ans); } return 0;}/*5hh.hh ..... H... Hhhhhh*/View Code
Scau 10327 Biggest Square