bzoj1661[usaco2006 Nov]big Square Huge Square
Test instructions
There are some J points, some B points, and some blank spots in the N*n diagram, and it is asked to add a J point to the blank to get 4 J points to make up the largest square area. N≤100.
Exercises
Enumerates two points and then tries to make a quadrilateral in 4 upper and lower two directions, based on the edges of the two points.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMAXN 1107 using namespacestd;8 9 CharGRAPH[MAXN][MAXN];intN,ans;Ten intMain () { Onescanf"%d", &n); Inc (I,1, N) scanf ("%s", graph[i]+1); AInc (I,1, N) Inc (J,1, N)if(graph[i][j]=='J'){ -Inc (k,i+1, N) { -Inc (L,1, J) { the intCnt=1; - if(graph[k][l]=='B')Continue;if(graph[k][l]=='J') cnt++; - intx=l-j,y=k-i; - if(k-x>n| | l+y>n| | graph[k-x][l+y]=='B')GotoJUMP1;if(graph[k-x][l+y]=='J') cnt++; + if(i-x>n| | j+y>n| | graph[i-x][j+y]=='B')GotoJUMP1;if(graph[i-x][j+y]=='J') cnt++; - if(cnt>=3) Ans=max (ans, (k-i) * (k-i) + (j-l) * (J-l)); + JUMP1:; A if(k+x<1|| l-y<1|| graph[k+x][l-y]=='B')GotoJUMP2;if(graph[k+x][l-y]=='J') cnt++; at if(i+x<1|| j-y<1|| graph[i+x][j-y]=='B')GotoJUMP2;if(graph[i+x][j-y]=='J') cnt++; - if(cnt>=3) Ans=max (ans, (k-i) * (k-i) + (j-l) * (J-l)); - JUMP2:; - } -Inc (l,j+1, N) { - intCnt=1; in if(graph[k][l]=='B')Continue;if(graph[k][l]=='J') cnt++; - intx=l-j,y=k-i; to if(k-x<1|| l+y>n| | graph[k-x][l+y]=='B')GotoJump3;if(graph[k-x][l+y]=='J') cnt++; + if(i-x<1|| j+y>n| | graph[i-x][j+y]=='B')GotoJump3;if(graph[i-x][j+y]=='J') cnt++; - if(cnt>=3) Ans=max (ans, (k-i) * (k-i) + (j-l) * (J-l)); the Jump3:; * if(k+x>n| | l-y<1|| graph[k+x][l-y]=='B')GotoJump4;if(graph[k+x][l-y]=='J') cnt++; $ if(i+x>n| | j-y<1|| graph[i+x][j-y]=='B')GotoJump4;if(graph[i+x][j-y]=='J') cnt++;Panax Notoginseng if(cnt>=3) Ans=max (ans, (k-i) * (k-i) + (j-l) * (J-l)); - Jump4:; the } + } A } theprintf"%d", ans);return 0; +}
20161023
bzoj1661[usaco2006 Nov]big Square Huge Square *