链接: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 Round #542(Div. 2) D1.Toy Train的更多相关文章

  1. Codeforces Round 542 (Div. 2)

    layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  2. 水题 Codeforces Round #303 (Div. 2) A. Toy Cars

    题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...

  3. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  4. Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】

    任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...

  5. Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...

  6. Codeforces Round #303 (Div. 2) A. Toy Cars 水题

     A. Toy Cars Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/problem ...

  7. Codeforces Round #238 (Div. 2) D. Toy Sum(想法题)

     传送门 Description Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to s ...

  8. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  9. Codeforces Round #542(Div. 2) CDE 思维场

    C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...

随机推荐

  1. vue 计算属性与侦听器

    侦听器:顾名思义,就是用来监听数据变化用的.侦听器在vue实例中,定义变量watch来使用.监听新值newVal和旧值oldVal,具体使用方法如下: <!DOCTYPE html> &l ...

  2. xcode编译 debug版或release 版

    编译debug版本或release 版本 在Run和Stop按钮的右边有一个工程名 点击工程名,选择Manage Schemes 选择Edit... 左侧选择Run ProjectName.app 右 ...

  3. Apache Qpid消息通讯模型和消息地址简介

    Broker知识准备 Broker内置两种节点类型:一种是 queue,一种是 topic. 1.  queue 节点能够缓存消息,直到被读取走为止.queue节点满足两个重要的 PTP 通信的特征, ...

  4. 距特征之k阶距概念

    k阶原点距和k阶中心距各是说明什么数字特征 http://www.cnblogs.com/emanlee/archive/2011/04/25/2028628.html 二阶中心距,也叫作方差,它告诉 ...

  5. string和int互相转化

    1 如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([ ...

  6. TiDB 是否支持其他存储引擎?

    https://www.pingcap.com/docs-cn/FAQ/ 1.1.11 TiDB 是否支持其他存储引擎? 是的,除了 TiKV 之外,TiDB 还支持一些流行的单机存储引擎,比如 Go ...

  7. mysql字符串的常用函数(截取和拼接)

    #截取字符串(先正序取2个,再倒序取1个)SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('aaa-gg-cc-dd','-',2),'-',-1) #获取子表某个字段的 ...

  8. Linux内核日志开关

    Linux内核日志开关 1.让pr_debug能输出 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -59,7 +59,7 ...

  9. stl里面的空间适配器

    一般而言,如果频繁地向system heap申请和释放空间很小的内存空间块(小于128B的),就会对系统内存资源产生很多内存碎片(fragment)的问题,而C++的::operator new() ...

  10. cassandra在服务端像leveldb一样进行插入初试成功

    经过研究,决定在 cql3/QueryProcessor.java 里面下手. 这里有两个函数,第一个是 public ResultMessage process(String queryString ...