HDU 2037 does not ac this summer

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2037

Greedy problem-selection of non-Intersecting intervals. 152 pages of the book.

(AI, Bi), after B is sorted in ascending order, greedy strategy: Be sure to select the first interval. Why.

Not AC this summer

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/others) total submission (s): 27976 accepted submission (s): 14837

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.) input data contains multiple test instances. The first line of each test instance has only one integer n (n <= 100 ), indicates the total number of programs you like to watch, followed by N rows of data. Each row includes two data ti_s, ti_e (1 <= I <= N ), the Start Time and end time of the first program, respectively. 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 input121 33 40 73 815 1915 2010 158 186 125 104 90 sample output5
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{    int s,e;}a[200];bool cmp(node a,node b){     return a.e<b.e;}int main(){    int n,i,ans;    while(~scanf("%d",&n)&&n)    {      for(i=0;i<n;i++)        scanf("%d%d",&a[i].s,&a[i].e);        sort(a,a+n,cmp);        ans=1;        int f=a[0].e;        for(i=1;i<n;i++)        {           if(a[i].s>=f)              {                 ans++;                 f=a[i].e;              }        }       printf("%d\n",ans);    }    return 0;}

 

 

HDU 2037 does 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.