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;
}

  

posted @ 2019-02-27 23:35  YDDDD  阅读(158)  评论(0编辑  收藏  举报