码迷,mamicode.com
首页 > 其他好文 > 详细

D1.Toy Train

时间:2019-02-28 00:50:42      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:sort   force   cos   type   push   highlight   ++   cost   mes   

链接: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;
}

  

D1.Toy Train

标签:sort   force   cos   type   push   highlight   ++   cost   mes   

原文地址:https://www.cnblogs.com/YDDDD/p/10447814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!