(~ ̄▽ ̄) ~*
//ask for a set, the intersection of this set with any interval, at least two digits//greedy Process: According to the right value of n intervals from small to large to arrange the interval,//The collection first takes the right two digits of the first interval,//to the second interval, judging whether the number in the set is in the interval//if not, take the right from the second interval to the left (Cnt=0 takes the last two digits, Cnt=1 takes the last number)#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>using namespacestd;structinterval{intL,r;} a[10005];BOOLcmp (interval a,interval b) {returna.r<B.R;}intMain () {intn,res=0; scanf ("%d",&N); for(intI=0; i<n;i++) scanf ("%d%d",&a[i].l,&A[I].R); Sort (A,a+n,cmp); Vector<int>Set; Set.push_back (a[0].r-1); Set.push_back (a[0].R); Res=2; for(intI=1; i<n;i++) { intCnt=0; for(intj=0; J<set.size (); j + +) { if(set[j]>=a[i].l&&set[j]<=A[I].R) CNT++; } if(cnt==0) {set.push_back (A[I].R-1); Set.push_back (A[I].R); Res+=2; } Else if(cnt==1) {set.push_back (A[I].R); Res++; }} printf ("%d\n", RES); return 0;}
POJ 1716 Integer intervals# greedy