码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3650 Hot Expo(贪心)

时间:2014-07-27 23:46:49      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:hdu   贪心   

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

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


----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣http://user.qzone.qq.com/593830943/main

----------------------------------------------------------------------------------------------------------------------------------------------------------

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
2 1 4 4 5 2 2 3 4 6 0
 
Sample Output
2 1
 
Source

题目意思:给你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;
}



hdu 3650 Hot Expo(贪心),布布扣,bubuko.com

hdu 3650 Hot Expo(贪心)

标签:hdu   贪心   

原文地址:http://blog.csdn.net/u012860063/article/details/38182843

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!