Usaco january--Rectangle [rects]

Source: Internet
Author: User

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 Output2because the data is small, so you can first delete the same rectangle, and then handle the time, the input to ensure that the length is less than the width, and then with a long sort, to find the longest non-descending sequence of width (originally can be written nlogn, but want to steal a lazy ~)
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <algorithm>5 using namespacestd;6 Const intmaxn=1005;intmaxx=0;7 intA[MAXN],B[MAXN],C[MAXN];8 BOOLMAP[MAXN][MAXN];9 structnode{Ten     intL,r; One }W[MAXN]; A intN; - BOOLCompConstNode &q,ConstNode &e) - { the     if(Q.L==E.L)returnq.r<E.R; -     returnq.l<E.L; - } - intMain () + { -Freopen ("recks.in","R", stdin); +Freopen ("Recks.out","W", stdout); Ascanf"%d",&n); at     inttemp=0; -      for(intI=1; i<=n;i++) -     { -         intx, y; -scanf"%d%d",&x,&y); -         if(map[x][y]==false) in         { -map[x][y]=true; tomap[y][x]=true; +W[++temp].l=x;w[temp].r=y; -             if(w[temp].l>w[temp].r) Swap (W[TEMP].L,W[TEMP].R); the         } *         Else Continue; $     }Panax NotoginsengSort (w+1, w+temp+1, comp); -      for(intI=1; i<=temp;i++) c[i]=1; the      for(intI=2; i<=temp;i++) +     { Amaxx=0; the          for(intj=1; j<i;j++) +         { -             if(w[i].r>w[j].r&&maxx<c[j]+1) $             { $maxx=c[j]+1; -c[i]=Maxx; -b[i]=J; the             } -             Else if(w[i].r==w[j].r&&w[i].l!=w[j].l&&maxx<c[j]+1)Wuyi             { themaxx=c[j]+1; -c[i]=Maxx; Wub[i]=J; -             } About         } $     } -     intpos=0; maxx=0; -      for(intI=1; i<=temp;i++) -     { A         if(c[i]>Maxx) +         { theMaxx=c[i];p os=i; -         } $     } the     intans=0; the      while(B[pos]) the     { theans++; -pos=B[pos]; in     } theprintf"%d", ans+1); the     return 0; About}

Usaco january--Rectangle [rects]

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.