hdu 3650 Hot Expo(贪心)

来源:互联网 发布:驴皮怎么熬制阿胶知乎 编辑:程序博客网 时间:2024/05/21 11:45

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3650



Problem Description
Sunny 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.
 
Input
The 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.
 
Output
Output the minimum days that Sunny should spend in visiting in a seperated line for each test case.
 
Sample Input
21 44 522 34 60
 
Sample Output
2 1
 
Source
2010 Asia Regional Hangzhou Site —— Online Contest 

题目意思:给你n个演出的起始时间st和结束时间en,要你求出最少需要多少天能看完全部的表演。。每一天都有相应的表演。


代码如下:
第一种:
#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;}

第二种:
#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;}



5 0
原创粉丝点击