"UVA 1312" cricket Field (algorithmic efficiency--skill enumeration)

Source: Internet
Author: User

Test Instructions: There are N trees in a l*r grid, asking for a maximum empty square and outputting its lower-left corner coordinates and length. (1≤l,r≤10000, 0≤n≤100)

Solution: Enumerating an empty square is the enumeration of an empty matrix, first to fix an edge, to continue the operation. (P.S. Many types of problems are like this: fix a variable first, then compare the other variable .) This kind of thought in greedy, DP and so on often appear, must grasp! So the problem is to enumerate the range of an edge (the horizontal axis), then enumerate the sorted points, and then compare and update the answers based on the current enumerated point and the ordinate of the largest point of the previous ordinate to get the length of the edge.

P.S, I've been playing this question for 2 hours!?? º· (? ?????????? )? º·? Must pay attention to the details Ah! And also...... My ranks are the opposite of the problem.

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <iostream>6 using namespacestd;7 8 Const intn= the, d=10010;9 intn,l,r,m;Ten structnode{intx, y;} A[n]; One intB[n]; A  - intMmin (intXintY) {returnX<y?x:y;} - intMmax (intXintY) {returnX>y?x:y;} the BOOLCMP (node X,node y) - { -     if(X.Y!=Y.Y)returnx.y<y.y; -     returnx.x<y.x; + } - intMain () + { A     intT; atscanf"%d",&T); -      while(t--) -     { -scanf"%d%d%d",&n,&r,&l); -m=1; b[1]=0; -        for(intI=1; i<=n;i++) in       { -scanf"%d%d", &a[i].y,&a[i].x);// tob[++m]=a[i].x; +       } -B[++m]=l;//No +1 ... theSort (A +1, A +1+n,cmp); *Sort (b +1, B +1+m); $       intp=1;Panax Notoginseng        for(intI=2; i<=m;i++) -         if(b[i]!=b[i-1]) b[++p]=B[i]; them=p; +        A       inttx=0, ty=0, ans=0; the        for(intI=1; i<=m;i++) +         for(intj=i+1; j<=m;j++) -        { $          intmxy=0, TMP; $           for(intk=1; k<=n;k++) -          { -             if(a[k].x<b[i]| | A[K].X&GT;B[J])Continue;//don't break it easily. theTmp=mmin (b[j]-b[i],a[k].y-mxy); -             if(Tmp>ans) {ans=tmp; tx=b[i]; ty=Mxy;}Wuyi             if(A[k].x!=b[i] && a[k].x!=b[j]) mxy=a[k].y; the          } -Tmp=mmin (B[J]-B[I],R-MXY);//Don't miss the border Wu          if(Tmp>ans) {ans=tmp; tx=b[i]; ty=Mxy;} -        } Aboutprintf"%d%d%d\n", Ty,tx,ans); $       if(T) printf ("\ n"); -     } -     return 0; -}

"UVA 1312" cricket Field (algorithmic efficiency--skill enumeration)

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.