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