2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Train Seats Reservation

You are given a list of train stations, say from the station 11 to the station 100100.

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 11 to the station 100100 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 11 to station 1010 can share a seat with another passenger from station 3030 to 6060.

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 as 10001000. After nn, there will be nn lines representing the nnreservations; each line contains three integers s, t, ks,t,k, which means that the reservation needs kk seats from the station ss to the station tt.These ticket reservations occur repetitively in the input as the pattern described above. An integer n = 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.

样例输入

2
1 10 8
20 50 20
3
2 30 5
20 80 20
40 90 40
0

样例输出

20
60
*

题目来源

2017 ACM-ICPC 亚洲区(南宁赛区)网络赛

很水的一个题,队友想得及其复杂,就是把1-100分成100段,分别是1-2,2-3,3-4……99-100

对输入的范围进行累加,输出值最大的那个单位段

#include <iostream>
//#include<math.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=110;
int train[maxn];

int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)
        {
            cout<<"*"<<endl;
            break;
        }
        memset(train,0,sizeof(train));
        int l,r,num;
        int maxsum=0;
        for(int j=0;j<n;j++)
        {


        cin>>l>>r>>num;
        for(int i=l;i<r;i++)
        {
            train[i]+=num;
        }
        for(int i=0;i<=100;i++)
        {
            maxsum=max(maxsum,train[i]);
        }

        }
        cout<<maxsum<<endl;
    }
    return 0;
}



原文地址:https://www.cnblogs.com/bryce1010/p/9387184.html