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)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...
随机推荐
- @Transactional 无效的解决方案
1 .在需要事务管理的地方加@Transactional 注解.@Transactional 注解可以被应用于接口定义和接口方法.类定义和类的 public 方法上 . 2 . @Transactio ...
- ribbon负载均衡进行服务消费
相同服务以不同端口形式注册到eureka上,ribbon从eureka上获取冰进行服务消费,会偶现如下现象: I/O error on GET request for "http://COM ...
- PandoraBox 支持3G无线上网卡(联通卡3G卡)(一)
一:笔者采用的是系统是OpenWrt之PandoraBox,内核版本3.3.8:硬件设备是MTK的7620开发板. 其中怎么搭建openwrt开发环境在此不用多说,因为既然想实现3G无线上网卡拨号上网 ...
- [PHP]PDO调用存储过程
1. 数据库中已创建存储过程user_logon_check, PHP调用示例如下, <?php $dsn = 'mssql:dbname=MyDbName;host=localhost'; $ ...
- git常用知识笔记
学习资料: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 http://codi ...
- MySQL的简单优化
一.如何发现需要优化的SQL 主要使用MySQL的慢查日志对有效率问题的SQL进行监控 第一步:启动慢查日志的监控 打开开关,将未使用索引的查询记录到慢查日志中 设置查询时间,当查询时间大于这个值,就 ...
- 使用Mock.js进行独立于后端的前端开发
Mockjs能做什么? 基于 数据模板 生成模拟数据. 基于 HTML模板 生成模拟数据. 拦截并模拟 ajax 请求. 能解决的问题 开发时,前后端进度不同步,后端还没完成数据输出,前端只好写静态模 ...
- 用WaveX实现音频文件的录音
原文地址:https://blog.csdn.net/gongluck93/article/details/53096013 1.WaveInOpen waveInOpen MMRESULT wave ...
- (linux)platform_driver_probe与platform_driver_register的区别
[驱动注册]platform_driver_register()与platform_device_register() 设备与驱动的两种绑定方式:在设备注册时进行绑定及在驱动注册 ...
- html5--6-28 css盒模型4
html5--6-28 css盒模型4 实例 学习要点 了解盒模型 元素内容.内边距.边框 和 外边距 了解盒模型的概念: CSS 盒模型规定了处理元素内容.内边距.边框 和 外边距 的方式. 最内部 ...