HDU 3650 hot Expo (Greedy)

Source: Internet
Author: User

Reprint please indicate the source: http://blog.csdn.net/u012860063? Viewmode = Contents

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3650


----------------------------------------------------------------------------------------------------------------------------------------------------------
Welcome to tianci Hut: http://user.qzone.qq.com/593830943/main
 
----------------------------------------------------------------------------------------------------------------------------------------------------------

Problem descriptionsunny wants to go to the Shanghai Expo this month and he intends to visit N (1 <= n <= 100) Country pavilions. as we all know, in each pavilion, there is always a wonderful performance every day. every performance will always be played only one time each day. and performance I begins at beg [I] Second and ends at end [I] Second (0 <= beg [I], end [I] <24*3600 ). sunny can not visit more than one country pavilion at the same time. sunny wouldn't like to miss any performance in the country pavilions that he plans to visit. however, it's also well known that getting accommodation in Shanghai is a little expensive, so he has to make a good arrangement to make his staying time (in days) There minimum.
Inputthe input contains several test cases. each test case begins with an integer number n. then n lines follow and each contains two integers representing the begin time and end time of the performance in the corresponding day.
Input is terminated by a value of zero (0) for N.
Outputoutput the minimum days that Sunny shoshould spend in visiting in a seperated line for each test case.
Sample Input
21 44 522 34 60
Sample output
2 1
Source2010 Asia Regional Hangzhou site -- online contest
Give you the start time (ST) and end time (en) of N performances. You need to find the minimum number of days to complete the performances .. Each day has a corresponding performance.


The Code is as follows:
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;struct Time{    int s, e;    int f;}a[117];bool cmp(Time x, Time y){    if(x.s == y.s)        return x.e < y.e;    return x.s < y.s;}int main(){    int n;    int t, i, j, k, flag;    while(scanf("%d",&n) && n)    {        for(i = 1; i <= n; i++)        {            scanf("%d %d",&a[i].s,&a[i].e);            a[i].f = 0;        }        sort(a+1,a+n+1,cmp);        int num, ans, td;        num=n,ans=0;        while(num)        {            ans++;            td=-1;            for(i = 1; i <= n; i++)            {                if(!a[i].f && a[i].s > td)                {                    td=a[i].e;                    a[i].f = 1;                    num--;                }            }        }        printf("%d\n",ans);    }    return 0;}

Second:
#include<stdio.h>#include<string.h>int max(int a,int b){return a>b?a:b;}int main(){int n;int c[3600*24+10];int maxnum=3600*24,i,a,b;int maxx;while(scanf("%d",&n),n){memset(c,0,sizeof(c));while(n--){scanf("%d%d",&a,&b);for(i=a;i<=b;i++){c[i]++;}}maxx=c[0];    for(i=1;i<maxnum;i++){maxx=max(maxx,c[i]);}printf("%d\n",maxx);}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.