Hot Expo
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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.
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#include <iostream>
#include<cstdio>
using namespace std;int l[86405];int main()
{
int n,p,q,i,j,tmp;
while(cin >> n)
{
if(n == 0) break;
memset(l,0,sizeof(l));
for(i = 0; i < n; i++)
{
scanf("%d %d",&p,&q);
if(p > q)
tmp = p, p = q, q = tmp;
for(j = p; j <= q; j++)
{
l[j]++;
}
}
tmp = -1;
for(i = 0; i < 86405; i++)
{
if(l[i] > tmp)
tmp = l[i];
}
printf("%d/n",tmp);
}
return 0;
}
本文介绍了一个解决游园安排问题的算法案例。该算法旨在帮助用户在有限的时间内参观多个场馆,确保不错过任何表演的同时,尽可能减少在园区内的停留天数。通过输入每个场馆表演的开始和结束时间,算法能够计算出所需的最少天数。
132

被折叠的 条评论
为什么被折叠?



