"The greedy flood problem" bzoj3410-[usaco2009 dec]selfish grazing The selfish grass-eater

Source: Internet
Author: User

"The main topic"

Given n intervals, ask how many intervals are selected so that they do not overlap one another.

Ideas

Water problem quq improve mood. Sort by the right endpoint size, updating the last right endpoint at a time, if the current left endpoint is greater than the last right endpoint is preferable.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intmaxn=50000+ -;7 structnode8 {9     intL,r;Ten     BOOL operator< (ConstNode &x)Const One     { A         return(r<X.R); -     } - }COW[MAXN]; the intN; -  - intMain () - { +scanf"%d",&n); -      for(intI=0; i<n;i++) scanf ("%d%d",&cow[i].l,&COW[I].R); +Sort (cow,cow+n); A     intr=-1, ans=0; at      for(intI=0; i<n;i++) -     { -         if(cow[i].l>=R) -         { -R=COW[I].R; -ans++; in         } -     } tocout<<ans<<Endl; +     return 0; -}

"Greedy flood problem" bzoj3410-[usaco2009 dec]selfish grazing selfish grass eater

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.