hdu 3650 Hot Expo(贪心)

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

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

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋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

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

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

时间: 2024-10-12 13:58:46

hdu 3650 Hot Expo(贪心)的相关文章

hdu 4296 Buildings(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1822    Accepted Submission(s): 722 Problem Description Have you ever heard the sto

hdu 4864 Task (贪心)

# include <stdio.h> # include <algorithm> # include <string.h> using namespace std; struct node { int t; int v; int yy; }; struct node a[100010],b[100010]; bool cmp(node a1,node a2) { if(a1.t==a2.t)//先按时间从大到小 return a1.v>a2.v;//再按水平从大

HDU 5014 Number Sequence 贪心 2014 ACM/ICPC Asia Regional Xi&#39;an Online

尽可能凑2^x-1 #include <cstdio> #include <cstring> const int N = 100005; int a[N], p[N]; int init(int x) { int cnt = 0; while(x > 1) { x /= 2; cnt ++; } return cnt + 1; } int main() { int n; while(~scanf("%d", &n)){ for(int i = 0;

HDU 4903 (模拟+贪心)

Fighting the Landlords Problem Description Fighting the Landlords is a card game which has been a heat for years in China. The game goes with the 54 poker cards for 3 players, where the “Landlord” has 20 cards and the other two (the “Farmers”) have 1

HDU 1045 Fire Net 贪心

Problem Description Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small castle that has four openings through wh

HDU 1338 Game Prediction 贪心

Problem Description Suppose there are M people, including you, playing a special card game. At the beginning, each player receives N cards. The pip of a card is a positive integer which is at most N*M. And there are no two cards with the same pip. Du

hdu 1009 FatMouse&#39; Trade(贪心)

题目来源:hdu 1009 FatMouse' Trade FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 54581 Accepted Submission(s): 18299 Problem Description FatMouse prepared M pounds of cat food, ready

hdu 4925 Apple Tree(贪心)

http://acm.hdu.edu.cn/showproblem.php?pid=4925 尽量让每棵苹果树周围都施肥,每次找到一个空地种上苹果树之后,使其周围的空地施肥,不再种苹果树. #include <stdio.h> #include <iostream> #include <map> #include <set> #include <list> #include <stack> #include <vector>

hdu 4915 Parenthese sequence (贪心+模拟)

题目大意: 一个序列中有左括号和右括号,还有问号,问号可以任意转换成左右括号. 问这个序列有多少种情况的转变使得这个序列变成合法的括号匹配序列. 思路分析: 首先我们分析一下,如何使得一个序列是合法的括号匹配序列. 我们很容易想到的是用栈模拟匹配过程. 当遇到左括号就进栈,当遇到右括号就让栈顶的左括号出栈. 那么在模拟的过程中,造成这个序列的不合法的原因只有当右括号来的时候,此时的栈已经为空. 这里补充一句,一旦一个序列给定,那么这里面的问号有多少变成左括号,多少变成右括号,是一定的. 看完以上