zoukankan      html  css  js  c++  java
  • Codeforces Round #542(Div. 2) D1.Toy Train

    链接:https://codeforces.com/contest/1130/problem/D1

    题意:

    给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果。

    求从每个位置开车的最小的时间。

    思路:

    vector记录每个位置运送完拥有糖果的时间消耗,为糖果数-1 * n 加上消耗最少时间的糖果。

    对每个起点进行运算,取所有点中的最大值。

    代码:

    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long LL;
    const int MAXN = 200 + 10;
    
    vector<int> station[MAXN];
    int train[MAXN];
    
    int main()
    {
        int n, m;
        int s, c;
        scanf("%d%d", &n, &m);
        for (int i = 1;i <= m;i++)
        {
            scanf("%d%d", &s, &c);
            int cost;
            if (s <= c)
                cost = c - s;
            else
                cost = n - (s - c);
            station[s].push_back(cost);
        }
        for (int i = 1;i <= n;i++)
            sort(station[i].begin(), station[i].end());
        for (int i = 1;i <= n;i++)
        {
            int res = -1;
            for (int j = 1;j <= n;j++)
            {
                if (!station[j].size())
                    continue;
                int cost;
                if (i <= j)
                    cost = j - i;
                else
                    cost = n - (i - j);
                int k = station[j].size() - 1;
                cost += k * n;
                cost += station[j][0];
                res = max(res, cost);
            }
            printf("%d ", res);
        }
    
    
        return 0;
    }
    

      

  • 相关阅读:
    codeforces 862B
    codeforces 863B
    codeforces 864B
    codeforces 867B
    codeforces 868B Race Against Time
    codeforces 869B The Eternal Immortality
    CodeForces
    nyoj 括号配对问题(模拟栈的过程)
    HDU
    nyoj 119 士兵杀敌(三)线段树
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10447814.html
Copyright © 2011-2022 走看看