zoukankan      html  css  js  c++  java
  • 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B题

    2017-09-24 19:16:38

    writer:pprp

    题目链接:https://www.jisuanke.com/contest/877

    题目如下:

    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
    *

    分析:这是一个求解重叠区间最大和的问题,签到题...ai
    将起点设为正数,终点设为负数,扫描一遍就可以知道区间中最大值

    代码如下:
    //ac B
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    
    const int maxn = 105;
    int a[maxn];
    
    int main()
    {
        freopen("in.txt","r",stdin);
        int n;
        while(cin>>n)
        {
            if(n==0)
            {
                cout<<"*"<<endl;
                break;
            }
    
            memset(a,0,sizeof(a));
    
            while(n--)
            {
                int s,t,k;
                cin>>s>>t>>k;
                a[s]+=k;
                a[t]-=k;
            }
            int ans=0,temp=0;
            for(int i=1; i<=100; i++)
            {
                temp+=a[i];
                ans=max(ans,temp);
            }
    
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    mybatis N+1问题解决
    Best Time to Buy and Sell Stock
    119. Pascal's Triangle II
    HBuilder打包ios
    关于JavaScript/TypeScript中的setTimeout和setInterval
    白色透明渐变css
    AntV 在小程序中的使用
    AntV 在h5页面中的使用
    js处理后端返回超过16位大数字方案(network中preview和response返回不一致)
    m站taro编译css的时候有些属性会被编译掉,如果遇到这个问题,用第一行代码,写到无法编译的代码上面
  • 原文地址:https://www.cnblogs.com/pprp/p/7588171.html
Copyright © 2011-2022 走看看