[Cpp]/* topic general idea: Give the start time and end time of a program, and find the maximum number of complete programs to watch * solution: sort by program time first, because it must be a complete program, therefore, you must select the first program to start and end as soon as possible after the last program ends. */# Include <cstdio> # include <cstring> # include <algorithm> using namespace std; # define MAX 101 struct node {int x, y;} a [MAX], B [MAX]; bool cmp (node a, node B) {if (. x! = B. x) {return. x <B. x;} else {return. y <B. y ;}} int main (int argc, char const * argv []) {# ifndef ONLINE_JUDGE freopen ("test. in "," r ", stdin); # endif int cnt, ans; while (scanf (" % d ", & cnt), cnt) {ans = 0; for (int I = 0; I <cnt; I ++) scanf ("% d", & a [I]. x, & a [I]. y); sort (a, a + cnt, cmp); for (int I = 0; I <cnt; I ++) {if (! I) B [++ ans] = a [I]; else {if (a [I]. x> = B [ans]. y) {// the start time is later than the end time of the program. Add B [++ ans] = a [I];} else if (a [I]. y <B [ans]. y) {// if the end time is earlier than the end time of the program, replace B [ans] = a [I] ;}} printf ("% d \ n ", ans);} return 0 ;}