UVA-1312 Cricket Field Construction

Source: Internet
Author: User

The main idea: there are n trees in a w * H grid, asking you to find the largest square in this grid, which cannot have a tree inside, and there can be trees on the edge.

Problem-solving ideas: Just beginning to think of violence to enumerate each point, the results found wrong, in fact, this problem is like UVA-1382 distant galaxy this problem, but this is to find a square, looking for a square and look like a rectangle, only need to take the smallest side of the rectangle can be

#include <cstdio>#include <algorithm>using namespace STD;#define MAXNstructpoint{intx, y;} P[MAXN];intN, W, H, Y[MAXN];BOOLcmpConstPoint A,ConstPoint B) {if(a.x = = b.x)returnA.y < B.y;returna.x < b.x;}voidInit () {scanf("%d%d%d", &n, &w, &h); for(inti =0; I < n; i++) {scanf("%d%d", &p[i].x, &AMP;P[I].Y);    Y[i] = p[i].y; } Y[n] =0, Y[n +1] = H; Sort (y, y + n +2); Sort (p, p + N, CMP);}voidSolve () {intAns =0, XX, yy;intm = Unique (y, y + n +2)-Y; for(inti =0; I < m; i++) for(intj = i +1; J < M; J + +) {inth = y[j]-y[i], pre =0, W; for(intK =0; K < n; k++) {if(p[k].y <= Y[i] | | p[k].y >= Y[J])Continue; W = p[k].x-pre;if(Ans < min (w, h))                    {ans = min (w,h);                    xx = pre;                yy = Y[i];            } pre = p[k].x; } w = W-pre;if(Ans < min (h, W))                {ans = min (h,w);                xx = pre;            yy = Y[i]; }               }printf("%d%d%d\n", xx, yy, ans);}intMain () {intTestscanf("%d", &test); while(test--)        {init (); Solve ();if(test)printf("\ n"); }return 0;}

UVA-1312 Cricket Field Construction

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.