3359: [Usaco2004 Jan] Rectangle

Source: Internet
Author: User

3359: [Usaco2004 Jan] Rectangular time limit:10 Sec Memory limit:128 MB
Submit:8 Solved:5
[Submit] [Status] [Discuss] Description gives the N rectangle (1≤n≤100) and its length and width (not more than 1000), write a program to find the largest k, so that there is a K rectangle satisfies the layer contains the relationship, that is, the inner rectangle is contained by all outer rectangles. One rectangle P1 contains another rectangle P2, and the side of the P2 is less than the P1 side, and the other side of the P9 does not exceed the other side of P1. If two rectangles are the same, they are considered not included.    A rectangle of 2 x 1 is enclosed by a 2x2 rectangle and not by a 1 x 2 rectangle. Note: The order of the rectangles can be arbitrary, and the rectangle can be rotated.    Input line 1th: integer n. 2nd to n+1: The length and width of the rectangle are integers. Output row with the maximum number of k.sample Input4
8 14
16 28
29 12
14 8
Sample Output2
HINT Source

Orange

In fact, there is obviously a better way, but I still tease the establishment of a topology diagram (A-->b said a held in B inside, for convenience, I also made a -1*-1 rectangle as the source), and then to use SPFA to find out from the source point of the longest path of each point, and then find the maximum value can be

1 type2Point=^node;3Node=Record4 G,w:longint;5 Next:point;6         End;7 var8 I,j,k,l,m,n,f,r:longint;9 P:point;TenA:Array[0..10000,1..2] ofLongint; OneB:Array[0..10000] ofPoint ; AC,g:Array[0..10000] ofLongint; -D:Array[0..100000] ofLongint; - procedureAdd (x,y,z:longint); inline; the         varP:point; -         begin -New (p);p ^.g:=y;p^.w:=Z; -p^.next:=b[x];b[x]:=p; +         End; - procedureSwapvarx,y:longint); inline; +         varZ:longint; A         begin atz:=x;x:=y;y:=Z; -         End; - proceduresort (l,r:longint); inline; -         varI,j,x,y:longint; -         begin -i:=l;j:=r;x:=a[(L+r)Div 2,1];y:=a[(L+r)Div 2,2]; in                 Repeat -                          while(A[i,1]&LT;X)or(A[i,1]=X) and(A[i,2]<y)) DoInc (i); to                          while(A[j,1]&GT;X)or(A[j,1]=X) and(A[j,2]>y)) DoDec (j); +                         ifI<=j Then -                                 begin theSwap (A[i,1],a[j,1]); *Swap (A[i,2],a[j,2]); $ Inc (I);d EC (j);Panax Notoginseng                                 End; -                 untilI>J; the                 ifI<r Thensort (i,r); +                 ifL<j Thensort (l,j); A         End; the begin + READLN (n); -          fori:=1  toN Do $                 begin $READLN (A[i,1],a[i,2]); -                         ifA[i,1]>a[i,2] ThenSwap (A[i,1],a[i,2]); -                 End; thea[n+1,1]:=-1; a[n+1,2]:=-1; n:=n+1; -Sort1, n);Wuyi          fori:=1  toN Dob[i]:=Nil; the          fori:=1  toN-1  Do -                  forj:=i+1  toN Do Wu                         if(A[j,2]>a[i,2])or(A[j,2]>=a[i,2]) and(A[j,1]>a[i,1])) Then -                                 begin AboutAdd (I,j,1); $                                 End; -f:=1; r:=2;d [1]:=1; g[1]:=1; -Fillchar (C,sizeof (c),0); -          whileF<r Do A                 begin +p:=B[d[f]]; the                          whileP<>Nil  Do -                                 begin $                                         if(C[D[F]]+P^.W) &GT;C[P^.G] Then the                                                 begin thec[p^.g]:=p^.w+C[d[f]]; the                                                         ifg[p^.g]=0  Then the                                                                 begin -g[p^.g]:=1; ind[r]:=p^.g; the Inc (R); the                                                                 End; About                                                 End; thep:=P^.next; the                                 End; theg[d[f]]:=0; + Inc (f); -                 End; thel:=0;Bayi          fori:=1  toN Do ifC[i]>l Thenl:=C[i]; the Writeln (l); the End.

3359: [Usaco2004 Jan] Rectangle

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.