# bzoj1661[Usaco2006 Nov]Big Square 巨大正方形*

bzoj1661[Usaco2006 Nov]Big Square 巨大正方形

n*n的图中有一些J点，一些B点和一些空白点，问在空白点添加一个J点所能得到的有4个J点组成最大正方形面积。n≤100。

 1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #include <queue>
5 #define inc(i,j,k) for(int i=j;i<=k;i++)
6 #define maxn 110
7 using namespace std;
8
9 char graph[maxn][maxn]; int n,ans;
10 int main(){
11     scanf("%d",&n); inc(i,1,n)scanf("%s",graph[i]+1);
12     inc(i,1,n)inc(j,1,n)if(graph[i][j]=='J'){
13         inc(k,i+1,n){
14             inc(l,1,j){
15                 int cnt=1;
16                 if(graph[k][l]=='B')continue; if(graph[k][l]=='J')cnt++;
17                 int x=l-j,y=k-i;
18                 if(k-x>n||l+y>n||graph[k-x][l+y]=='B')goto jump1; if(graph[k-x][l+y]=='J')cnt++;
19                 if(i-x>n||j+y>n||graph[i-x][j+y]=='B')goto jump1; if(graph[i-x][j+y]=='J')cnt++;
20                 if(cnt>=3)ans=max(ans,(k-i)*(k-i)+(j-l)*(j-l));
21                 jump1:;
22                 if(k+x<1||l-y<1||graph[k+x][l-y]=='B')goto jump2; if(graph[k+x][l-y]=='J')cnt++;
23                 if(i+x<1||j-y<1||graph[i+x][j-y]=='B')goto jump2; if(graph[i+x][j-y]=='J')cnt++;
24                 if(cnt>=3)ans=max(ans,(k-i)*(k-i)+(j-l)*(j-l));
25                 jump2:;
26             }
27             inc(l,j+1,n){
28                 int cnt=1;
29                 if(graph[k][l]=='B')continue; if(graph[k][l]=='J')cnt++;
30                 int x=l-j,y=k-i;
31                 if(k-x<1||l+y>n||graph[k-x][l+y]=='B')goto jump3; if(graph[k-x][l+y]=='J')cnt++;
32                 if(i-x<1||j+y>n||graph[i-x][j+y]=='B')goto jump3; if(graph[i-x][j+y]=='J')cnt++;
33                 if(cnt>=3)ans=max(ans,(k-i)*(k-i)+(j-l)*(j-l));
34                 jump3:;
35                 if(k+x>n||l-y<1||graph[k+x][l-y]=='B')goto jump4; if(graph[k+x][l-y]=='J')cnt++;
36                 if(i+x>n||j-y<1||graph[i+x][j-y]=='B')goto jump4; if(graph[i+x][j-y]=='J')cnt++;
37                 if(cnt>=3)ans=max(ans,(k-i)*(k-i)+(j-l)*(j-l));
38                 jump4:;
39             }
40         }
41     }
42     printf("%d",ans); return 0;
43 }

20161023

posted @ 2016-10-30 15:01  YuanZiming  阅读(309)  评论(0编辑  收藏  举报