zoukankan      html  css  js  c++  java
  • Train Seats Reservation

    You are given a list of train stations, say from the station  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 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, nnn, which can be as large as 1000. After nnn, there will be nnn lines representing the nnn reservations; each line contains three integers s,t,k, which means that the reservation needs k 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=0n = 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 亚洲区(南宁赛区)网络赛

    由于最多只有100个站,所以可以暴力。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #define ll long long
     5 using namespace std;
     6 const int N = 110;
     7 int a[N];
     8 int main() {
     9     int n;
    10     while(scanf("%d", &n) &&n) {
    11         int s, t, k;
    12         for(int i = 1; i <= n; i ++) {
    13             scanf("%d %d %d", &s, &t, &k);
    14             for(int j = s; j < t; j ++) {
    15                 a[j] += k;
    16             }
    17         }
    18         int ans = 0;
    19         for(int i = 1; i <= 100; i ++) {
    20             ans = max(ans, a[i]);
    21         }
    22         printf("%d
    ",ans);
    23         memset(a, 0, sizeof(a));
    24     }
    25     printf("*
    ");
    26     return 0;
    27 }
  • 相关阅读:
    sprintboot 发布
    springmvc 常用注解
    react-navigation使用技巧
    Windows 10提示你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问
    Python 精选文章
    自动化办公:python操作Excel
    VSCode 插件
    使用 Visual Studio Code(VSCode)搭建简单的Python+Django开发环境的方法步骤
    纯洁的微笑
    初进python世界之数据类型
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7588562.html
Copyright © 2011-2022 走看看