hdu 3650 Hot Expo(贪心)
2014-07-27 21:57
260 查看
转载请注明出处: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
Sample Output
Source
2010 Asia Regional Hangzhou Site
—— Online Contest
题目意思:给你n个演出的起始时间st和结束时间en,要你求出最少需要多少天能看完全部的表演。。每一天都有相应的表演。
代码如下:
第一种:
第二种:
题目链接: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
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(贪心)
- HDU 3650 Hot Expo(气球染色 , 贪心 )
- HDU 3650 Hot Expo(气球染色 , 贪心 )
- HDU3650 Hot Expo
- hdu 3650 Hot Expo(2010杭州网选题)
- HDU 3650 贪心+二分
- HDU 3650 Hot Expo
- HDU 3650 Hot Expo
- hdu 3650 Hot Expo 活动安排 共多少天能参观完
- hdu 3650 Hot Expo(TwoPointer)
- hdu 3650 Hot Expo
- HDU 3650 Hot Expo (数据比较小)
- HDU:3650 Hot Expo
- HDU 3650 Hot Expo(线段覆盖==离散化)
- HDU-1009 贪心
- HDU 4700 Flow (贪心)
- HDU 5821 Ball【贪心】
- HDU-1789 Doing Homework again 贪心问题 有时间限制的最小化惩罚问题
- hdu 1789 Doing Homework again 贪心
- HDU_1055 && POJ_2054 Color a Tree(贪心)