-09-2419:16:38
writer:pprp
题目链接:/contest/877
题目如下:
You are given a list of train stations, say from the station11to the station100100.
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 station11to the station100100after 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 station11to station1010can share a seat with another passenger from station3030to6060.
Input Format
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,nn, which can be as large as10001000. Afternn, there will bennlines representing thennreservations; each line contains three integerss, t, ks,t,k, which means that the reservation needskkseats from the stationssto the stationtt.These ticket reservations occur repetitively in the input as the pattern described above. An integern = 0n=0(zero) signifies the end of input.
Output Format
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.
样例输入
21 10 820 50 2032 30 520 80 2040 90 400
样例输出
2060*
分析:这是一个求解重叠区间最大和的问题,签到题...ai
将起点设为正数,终点设为负数,扫描一遍就可以知道区间中最大值
代码如下:
//ac B#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 105;int a[maxn];int main(){freopen("in.txt","r",stdin);int n;while(cin>>n){if(n==0){cout<<"*"<<endl;break;}memset(a,0,sizeof(a));while(n--){int s,t,k;cin>>s>>t>>k;a[s]+=k;a[t]-=k;}int ans=0,temp=0;for(int i=1; i<=100; i++){temp+=a[i];ans=max(ans,temp);}cout<<ans<<endl;}return 0;}