HDU2037 not AC this summer

Source: Internet
Author: User

Problem-solving ideas: The greedy question, the key breakthrough is that the end time of the program first

Order from small to large, then determine the start time of the later program

is greater than or equal to the end time of the previous qualifying program. See Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intMAXN = the;6 intN, CNT, TMP;7 8 structnode{9     intS, E;Ten }P[MAXN]; One  A intCMP (node A, node B) - { -     returnA.E <B.E; the } -  - intMain () - { +      while(~SCANF ("%d", &n) &&N) -     { +          for(inti =0; I < n; i++) A         { atscanf"%d%d", &p[i].s, &p[i].e); -         } -Sort (p, p+N, CMP); -TMP = p[0].E, cnt =0; -          for(inti =1; I < n; i++) -         { in             if(P[I].S >= tmp)//you can do that, too. -             { toCNT + +; +TMP = P[I].E;//TMP Stores the end time of the program -             } the         } *printf"%d\n", cnt+1);//CNT here to add 1 $     }Panax Notoginseng     return 0; -}
View Code

HDU2037 not AC this summer

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.