1312-cricket Field

Source: Internet
Author: User

The grid size of the problem is very large, it seems to need to be discretized, but in fact it is not needed. Because we can see that since there are no trees in the square, we might as well enumerate the trees directly. So we will take the vertical axis alone from small to large order, two-cycle can be enumerated in the upper and lower bounds of the rectangle, and then the key is the horizontal axis enumeration. Similarly, we will sort the horizontal axis, and then determine whether the corresponding ordinate is in the upper and lower bounds, through observation, if not, then this point is not in the current enumeration of the rectangle, so skip directly on it, so we only need a variable to dynamically maintain the left edge.

See the code for details:

#include <bits/stdc++.h>using namespace Std;int t,n,w,h,y[105],len;struct point{int x, y;} A[105];bool CMP (point A,point B) {return a.x < b.x | | (a.x = = b.x && a.y < B.Y);}    void Solve () {sort (a,a+n,cmp);    Sort (y,y+n+2); Len = Unique (y,y+n+2)-y;    Just reduce a bit of complexity int ansx,ansy,ans = -1,HH,WW;  for (int i=0;i<len;i++) {for (int j=i+1;j<len;j++) {hh = y[j]-y[i];//Rectangle height int cur_x            = 0;                for (int k=0;k<n;k++) {if ((a[k].y <= y[i] | | a[k].y >= Y[J]) continue; WW = a[k].x-cur_x; The width of the rectangle ww = min (ww,hh);                Take the largest square if (ans < ww) {ansx = cur_x; ansy = Y[i]; ans = ww;            } cur_x = a[k].x;            } ww = w-cur_x;            ww = min (ww,hh);            if (ans < ww) {ansx = cur_x; ansy = Y[i]; ans = ww; }}} printf ("%d%d%d\n", Ansx,ansy,ans);   if (T) printf ("\ n");}    int main () {scanf ("%d", &t);        while (t--) {scanf ("%d%d%d", &n,&w,&h);        for (int i=0;i<n;i++) {scanf ("%d%d", &a[i].x,&a[i].y); y[i] = a[i].y;} Y[n] = 0; Y[N+1] = h;    Add the boundary value, repeat does not matter, also want to go to heavy solve (); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

1312-cricket Field

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.