HDU2073 (violence) VS HDU5214 (greedy)

Source: Internet
Author: User

Test instructions: Give the n Group of L[i],r[i], and find out the maximum number that can be nested with each other;

Idea: 2073 array size is 100, pure violence can be, but attention to sort, according to the order of r from small to large;

5214 array size is 10000000, pure violence words Absolute timeout, but the request can find 3 groups when the output yes can, so from both sides greedy on the good, originally thought sort more convenient some, but tle, change to find the largest minimum is good;

Misunderstanding: I think is the graph theory, to find the longest path (Bellman-ford can find the longest road, as long as the right value to change to the opposite number can), in fact, apply to 2073, but overqualified, and sentenced very strict, easy to mle,tle;

2073 Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cstdlib>6 #defineRepu (I,A,B) for (int i=a;i<b;i++)7 #defineN 11008 #defineMOD 42949672969 #definell Long LongTen using namespacestd; One intVis[n]; A structS - { -     intL,r; the     BOOL operator< (Consts& p)Const -     { -         if(r = =P.R) -             returnL <P.L; +         returnR <P.R; -     } + } M[n]; A intMain () at { -     intt,n,a,b,c,d; -      while(cin>>n&&N) -     { -Repu (I,0, N) -Cin>>m[i].l>>M[I].R; inSort (m,m+n); -memset (Vis,0,sizeof(Vis)); to         intMAXN =0; +         intU = m[0].r,v= m[0].L; - //Repu (i,0,n) the //cout<<m[i].l<< "" <<m[i].r<<endl; *Repu (I,0, N) $         {Panax NotoginsengRepu (j,i+1, N) -             { the                 if(U <= m[j].l && v <m[j].l) +                 { AU =M[J].R; thev =M[J].L; +vis[i]++; -                 } $             } $vis[i]++; -             //cout<<vis[i]<<endl; -MAXN =Max (VIS[I],MAXN); the         } -cout<<maxn<<Endl;Wuyi     } the     return 0; -}
View Code

5214 Code:

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cmath>5 #defineMOD 42949672966 7 using namespacestd;8typedef unsignedintLL;9 intT;Ten intN; One Const intn=10000005; A LL s1,e1; - LL l1,r1,l2,r2; - LL Minl,minr,maxl,maxr; the LL a,b,c,d; - LL L[n],r[n]; - intMain () - { +scanf"%d",&T); -      while(t--) +     { ACin>>n>>s1>>e1>>a>>b>>c>>D; atl[1]=S1; -r[1]=E1; -minl=maxl=l[1]; -minr=maxr=r[1]; -          for(intI=2; i<=n; i++) -         { inl[i]=l[i-1]*a+b; -r[i]=r[i-1]*c+D; to             if(l[i]>R[i]) + swap (l[i],r[i]); -             if(R[I]&LT;MINR)///find the largest and smallest of the two groups, and then just compare them with the two groups. the             { *Minl=L[i]; $Minr=R[i];Panax Notoginseng             } -             if(l[i]>MaxL) the             { +Maxl=L[i]; AMaxr=R[i]; the             } +         } -         BOOLflag=false; $          for(intI=1; i<=n; i++) $         { -             if(l[i]>minr&&r[i]<MaxL) -             { theflag=true; -                  Break;Wuyi             } the         } -printf"%s\n", Flag?"YES":"NO"); Wu     } -     return 0; About}
View Code

HDU2073 (violence) VS HDU5214 (greedy)

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.