Scau 10327 Biggest Square

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.