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 Round #542(Div. 2) D1.Toy Train的更多相关文章
- Codeforces Round 542 (Div. 2)
layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- 水题 Codeforces Round #303 (Div. 2) A. Toy Cars
题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #542(Div. 2) CDE 思维场
C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...
随机推荐
- Boom!!!计算机系统,从理解到爆炸,Bomblab
进入文件夹下 ./bomb 開始执行炸弹 对于炸弹command not found之类的鬼畜情况: chmod 777 bomb 然后再执行炸弹 objdump -d bomb > bomb. ...
- HDOJ_1000
#include int main() { int i, j; while(scanf("%d%d", &i, &j) == 2) printf("%d\ ...
- 2016/06/02 网摘记录 svn 服务器端 客户端 安装使用
http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2408089.html http://www.cnblogs.com/xiaobaihom ...
- Vue 之 npm 及 安装的包
1 npm相关 1.1 npm 是 基于Node.js 的,所以要先安装Node.js 在浏览器地址栏输入https://nodejs.org/en/, 进入Node.js官网后,点击下载左边的稳定 ...
- Cooperating sequential processes》,这篇论文提出了大名鼎鼎的概念信号量,Java里面用于线程同步的wait/notify也是信号量的一种实现。
闲话高并发的那些神话,看京东架构师如何把它拉下神坛 https://mp.weixin.qq.com/s/lAqn8CfSRta9iSvOR1Le6w
- R学习-- 数组和矩阵
生成 4行5列的数组,逐列逐行赋值x = array(1:20, dim= c(4,5)) 依据已知向量生成二维数组i = array(c(1:3,3:1,4:6,5:7), dim=c(3,4))也 ...
- Windows ping源码
需要测试外网的联通性,想到了用ping.网上下载了ping的源代码,调试下整理如下: /******************************************************** ...
- Pyhton:List build-in function
列表是Python中的可迭代对象之一,在讲列表的内建函数之前我们可以自己在IDE上看看都有那些内建函数,我们可以在pycharm中使用代码及其运行结果如下: print(dir(list)) ['__ ...
- JQuery树形插件Dynatree的包装对象
这是JQuery Dynatree插件的包装对象,做了些改进和增强,增加了右键菜单,以及相应事件等扩展1. [代码]MagicDTree的基本使用 <SCRIPT type=text/javas ...
- codeforces A. Kitahara Haruki's Gift 解题报告
题目链接:http://codeforces.com/problemset/problem/433/A 题目意思:给定 n 个只由100和200组成的数,问能不能分成均等的两份. 题目其实不难,要考虑 ...