bzoj1661[usaco2006 Nov]big Square Huge Square *

Source: Internet
Author: User

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 *

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.