2017 ACM-ICPC 亞洲區(南寧賽區)網絡賽 B 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 3030to 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 nn reservations; 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 亞洲區(南寧賽區)網絡賽

題意:就是先給你一個數 n,表示將有 n 行,每行輸入三個數s,t,k表示將有 k 個人在 s 站上車,在 t 站下車,然後問你這個列車在本次行駛時最多需要多少個座位。

這題屬於需要思考的水題,希望童鞋們能獨立完成。


附代碼:


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
///o(っ。Д。)っ AC萬歲!!!!!!!!!!!!!!
const int maxn = 1000;
int ss[maxn] = {}, tt[maxn];


int main()
{
    int n;
    while(scanf("%d", &n) != EOF)
    {
        memset(ss, 0, sizeof(ss));
        memset(tt, 0, sizeof(tt));
        if(n == 0)
        {
            printf("*\n");
            break;
        }
        int u, v, k;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d %d %d", &u, &v, &k);
            ss[u] += k;
            tt[v] += k;
        }
        int sum = 0, maxx = 0;
        bool flag = false;
        for(int i = 1; i <= 104; i++)
        {
            sum += ss[i];
            sum -= tt[i];
            maxx = max(maxx, sum);
            //printf("i = %d   sum = %d\n", i, sum);
        }
        printf("%d\n", maxx);
    }
    return 0;
}

///參考數據,基本全過了就能AC
/*
4
1 20 60
5 10 12
10 60 20
60 80 40
3
1 20 60
5 10 12
60 80 40
2
1 10 8
20 50 20
3
2 30 5
20 80 20
40 90 40
5
10 60 10
26 40 30
40 60 60
20 30 20
20 60 20
*/



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章