zoukankan      html  css  js  c++  java
  • 2017ICPC南宁赛区网络赛 Train Seats Reservation (简单思维)

    You are given a list of train stations, say from the station 111 to the station 100100100.

    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 111 to the station 100100100 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 111 to station 101010 can share a seat with another passenger from station 303030 to 606060.

    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 100010001000. After nnn, there will be nnn lines representing the nnn reservations; each line contains three integers s,t,ks, t, ks,t,k, which means that the reservation needs kkk seats from the station sss to the station ttt .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
    *

    一开始当贪心做了。。。就很蠢。。。然后看都600+过了怎么肥四。。
    然后发现直接开个数字记录和再找最大值就好。。
    傻了傻了。。

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<cstring>
     6 using namespace std;
     7 long long vis[1005];
     8 bool cmp(long long a,long long b)
     9 {
    10     return a > b;
    11 }
    12 
    13 int main()
    14 {
    15     int n;
    16     while(~scanf("%d",&n))
    17     {
    18         if(n==0){
    19             printf("*
    ");
    20             break;
    21         }
    22         int s,t;
    23         long long k;
    24         memset(vis,0,sizeof(vis));
    25         for(int i=0;i<n;i++)
    26         {
    27             scanf("%d%d%lld",&s,&t,&k);
    28             for(int j=s;j<t;j++)
    29                 vis[j]+=k;
    30         }
    31         sort(vis+1,vis+101,cmp);
    32         printf("%lld
    ",vis[1]);
    33         
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    区块链开发之Corda训练营笔记12:Flow习题答案
    区块链开发之Corda训练营笔记11:Flow代码演示
    gitolite的部署
    python操作redis
    python多进程
    mysql索引
    mysql事务
    mysql外键
    mysql联合查询
    python常用模块之re模块(正则)
  • 原文地址:https://www.cnblogs.com/Annetree/p/7593862.html
Copyright © 2011-2022 走看看