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)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...
随机推荐
- centos下部署项目问题
最近写了商品管理的后台完成了一部分,用node+koa+mongodb搭建,现在想部署到自己的服务器上,部署的过程中遇到了一些坑.首先就是各种环境的搭建,搭建好了之后要把后台的代码传到服务器上运行,运 ...
- Spyder的汉化
我准备写下spyder的汉化问题:对于英文大佬,从来没得汉化问题,但是对于新手和英语差的来说,汉化还是有必要,至少用汉化过得软件能快速掌握软件等.后期会用软件了在慢慢习惯英文也不迟...哈哈哈哈.本文 ...
- 在vs2005中添加lib库的方法
方法一:在用到lib的地方加上 //强烈推荐这种方法.#pragma comment(lib,"libname.lib") 方法二: 点击菜单命令 “项目/属性”, ...
- sanic官方文档解析之streaming(流动,滚动)和class_based_views(CBV的写法)
1,streaming(流媒体) 1.1请求流媒体 Sanic允许你通过流媒体携带请求数据,如下,当请求结束await request.stream.read()就会返回None,仅仅只有post请求 ...
- Golang 现有的哲学中,要求你尽量手工处理所有的错误返回
更优雅的 Golang 错误处理 - Go语言中文网 - Golang中文社区 https://studygolang.com/articles/9407
- webservice client setTimeOut
一:eclipse生成的client,基于axis client_sub.getOptions().setTimeOutInMilliSeconds(1000*60); client_sub表示一个客 ...
- poj 3585 Accumulation Degree(二次扫描和换根法)
Accumulation Degree 大致题意:有一棵流量树,它的每一条边都有一个正流量,树上所有度数为一的节点都是出口,相应的树上每一个节点都有一个权值,它表示从这个节点向其他出口可以输送的最大总 ...
- js 原型继承和class继承
摘自http://www.liaoxuefeng.com/ 在传统的基于Class的语言如Java.C++中,继承的本质是扩展一个已有的Class,并生成新的Subclass. 由于这类语言严格区分类 ...
- 关于谷歌浏览器默认字体12px的解决方案
1. * Chrome 中文界面下默认会将小于 12px 的文本强制按照 12px 显示, 可通过加入 CSS 属性 -webkit-text-size-adjust: none; 解决. 超链接访问 ...
- FZU2150 Fire Game —— BFS
题目链接:https://vjudge.net/problem/FZU-2150 Problem 2150 Fire Game Accept: 2702 Submit: 9240 Time Li ...