概述
Problem Description
You are given a list of train stations, say from the station 1 to the station 100.
The passengers can order several tickets from one station to another before the train leaves the station one. We will issue one train from the station 1 to the station 100 after all reservations have been made. Write a program to determine the minimum number of seats required for all passengers so that all reservations are satisfied without any conflict.
Note that one single seat can be used by several passengers as long as there are no conflicts between them. For example, a passenger from station 1 to station 10 can share a seat with another passenger from station 30 to 60.
Input
Several sets of ticket reservations. The inputs are a list of integers. Within each set, the first integer (in a single line) represents the number of orders, n, which can be as large as 1000. After nn, there will be n lines representing the n reservations; each line contains three integers s,t,k, which means that the reservation needs kk seats from the station s to the station t.These ticket reservations occur repetitively in the input as the pattern described above. An integer n=0 (zero) signifies the end of input.
Output
For each set of ticket reservations appeared in the input, calculate the minimum number of seats required so that all reservations are satisfied without conflicts. Output a single star '*' to signify the end of outputs.
Sample Input
2
1 10 8
20 50 20
3
2 30 5
20 80 20
40 90 40
0Sample Output
20
60
*
题意:t 组数据,每组给出 n 个 s t k 形式的订单,表示从站 s到站 t 有 k 个人坐车,问完成这 n 个订单最少要多少个座位
思路:
问题实质是求最大区间覆盖的值,由于 s、t 的数据范围仅到 100,那么可以借助桶排的思想模拟来做
开一个 100 的桶,扫描所有订单,将 s 的位置加入 k,代表有 k 个人上车,将 t 的位置减去 k,代表有 k 个人下车
最后从前向后扫描整个桶,记录桶的最大值即可
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; }
LL quickModPow(LL a,LL b,LL mod){ LL res=1; a=a%mod; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1;} return res; }
LL getInv(LL a,LL mod){ return quickModPow(a,mod-2,mod); }
const double EPS = 1E-10;
const int MOD = 1E9+7;
const int N = 100+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int bucket[N];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==0){
printf("*n");
break;
}
memset(bucket,0,sizeof(bucket));
for(int i=1;i<=n;i++){
int s,t,k;
scanf("%d%d%d",&s,&t,&k);
bucket[s]+=k;
bucket[t]-=k;
}
int res=0;
int sum=0;
for(int i=1;i<=100;i++){
sum+=bucket[i];
res=max(sum,res);
}
printf("%dn",res);
}
return 0;
}
最后
以上就是幸福店员为你收集整理的Train Seats Reservation(2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B)Problem DescriptionInputOutputSample InputSample OutputSource Program的全部内容,希望文章能够帮你解决Train Seats Reservation(2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B)Problem DescriptionInputOutputSample InputSample OutputSource Program所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复