Hdu2037 not ac this summer [greedy]

Source: Internet
Author: User

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;}


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.