This summer vacation without actime limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 27470 accepted submission (s): 14499
Problem description "this summer is not ac ?"
"Yes ."
"What are you doing ?"
"Watching the World Cup, dumb !"
"@ # $ % ^ & * % ..."
Indeed, the World Cup and fans have a holiday. It is estimated that many acmers will leave their computers away and rush to TV.
As fans, you must watch as many complete competitions as possible. Of course, as a good young man in the new age, you will certainly watch other programs, for example, news broadcast (never forget to care about national events), cat6 + 7, Super Girl, and Wang xiaoya's kaixindictionary, suppose you already know the broadcast schedules of all the TV programs you like to watch. Will you arrange them properly? (The goal is to watch as many complete programs as possible)
The input data contains multiple test instances. The first line of each test instance has only one integer n (n <= 100), indicating the total number of programs you like to watch, then there are n rows of data, each line contains two data ti_s, ti_e (1 <= I <= N), indicating the start time and end time of the first program, in order to simplify the problem, each time is represented by a positive integer. N = 0 indicates that the input is over and is not processed.
Output for each test instance, the number of TV programs that can be fully viewed is output, and the output of each test instance occupies one line.
Sample Input
121 33 40 73 815 1915 2010 158 186 125 104 142 90
Sample output
5
Water
#include <stdio.h>#include <algorithm>#define maxn 102using std::sort;struct Node{int l, r;} arr[maxn];bool cmp(Node a, Node b){return a.r < b.r;}int main(){int n, i, ans, flag;while(scanf("%d", &n), n){for(i = 0; i < n; ++i)scanf("%d%d", &arr[i].l, &arr[i].r);sort(arr, arr + n, cmp);flag = arr[0].r; ans = 1;for(i = 1; i < n; ++i)if(arr[i].l >= flag){++ans; flag = arr[i].r;}printf("%d\n", ans);}return 0;}