B. Train Seats Reservation ACM-ICPC Asia (Nanning Division) online Race

Source: Internet
Author: User
Tags ticket

You is 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'll issue one train from the station 1 through all reservations has been made. Write a program to determine the minimum number of seats required for all passengers so, all reservations is Satisfie D without any conflict.

Note that one single seat can is used by several passengers as long as there is no conflicts between them. For example, the a passenger from Station 1 to station can share a seat with another passenger from station to 60.

Input Format

Several sets of ticket reservations. The inputs is a list of integers. Within each set, the first integer (in a) represents the number of orders, NN, which can is as large as 100010 After nn, there'll be nn lines representing the NN reservations; Each line contains three integers s, T, Ks,t,k, which means 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 this all Rese Rvations is 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
0
Sample output

20
60

Topic Analysis:
There are 1-100 sites, passengers will place orders from the s site to the T site in the K -seat, different intervals between the seats can be freely shared, such as from the 1-30-site seat can be given to 50-80 of the passengers of the site. The topic asked us to find out the minimum number of seats required in each sample.

Note: 1-10 of seats can also be given to 10-20 of passengers

My train of thought:
For each of the sites are calculated:

Because the data is small, interval coverage, an interval of the required number of seats to cover each site up, so that when all the interval is covered, all the stations need to have a peak number of seats, the peak is what we want.

Full code:

 #include <stdio.h> #include <string.h> #define MAX int main (void) {int n, S,
    T, K, Max, Seat[max];
        while (scanf ("%d", &n)!=eof) {max = 0;
        memset (seat, 0, sizeof (int) *max);
            if (n = = 0) {printf ("*\n");
        Break
            } while (n--> 0) {scanf ("%d%d%d", &s, &t, &k);
        for (int i = s; i < T; i++) seat[i] + = k;
        } for (int i = 1; i < Max; i++) {if (Seat[i] > Max) MAX = Seat[i];
    } printf ("%d\n", Max);
} return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.