链接: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. Linux input子系统实例分析(一)

    这是一个简单的输入设备驱动实例.这个输入设备只有一个按键,按键被连接到一条中断线上,当按键被按下时,将产生一个中断,内核将检测到这个中断,并对其进行处理.该实例的代码如下:     1: #inclu ...

  2. 给EasyUi的Form加入自己主动填充部分输入框的方法

    依据项目须要,基于获取的数据对Form的部分输入框进行填充,而默认的EasyUI的Form 没有该方法.仅仅能一个输入框一个输入框的直接赋值,为此添加了Form对象的setValues,实现依据给定的 ...

  3. Domino函件收集器的配置及使用方法

     [背景] 今天一个朋友问我这样一个问题,他们OA的应用数据库和接口数据库部署在两台不同的server. 接口server主要负责和第三方系统进行集成,第三方系统调接口创建OA单据,OA系统进行审 ...

  4. 用 querySelectorAll 来查询 DOM 节点

    用 querySelectorAll 来查询 DOM 节点 Document.querySelectorAll - Web API 接口 | MDN https://developer.mozilla ...

  5. hadoop yarn namenode datanoe 启动异常问题解决 分析日志

    cat logs/hadoop-root-datanode-hadoop1.log ********************************************************** ...

  6. 合肥 专业做APP(安卓,ios) 微信公共平台

    合肥 专业做APP(安卓,ios) 微信公共平台 电话:15715696592

  7. linux kfifo移植

    先挖个坑,自己慢慢来填. 参考:http://blog.csdn.net/linyt/article/details/5764312 参考:http://www.cnblogs.com/Anker/p ...

  8. 可加装广告的swf播放器JS代码

    加载flash动画前可以加载代码,设定广告显示秒数这些,还有些小bug,等有空了修复好法上来给大家​​ 1. [代码][Java]代码<!DOCTYPE html PUBLIC "-/ ...

  9. hdu-2680 Choose the best route(最短路)

    题目链接: Choose the best route Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K ( ...

  10. I.MX6 wpa_supplicant_8 编译问题

    /************************************************************************ * I.MX6 wpa_supplicant_8 编 ...