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)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...
随机推荐
- openwrt - squashfs-sysupgrade.bin 的生成过程
squashfs-sysupgrade.bin 生成过程图 路径变量 $(KERNEL_BUILD_DIR)="/home/sam/Projects/openwrt-mt7620n/buil ...
- xamarin.android searchview的一些用法
前言 searchview是安卓常用的搜索控件,网上有很多关于searchview都是java的,所以我参看xamaroin官网的一些demo总结一些方法. 导读 1.如何创建一个searchview ...
- SpringMVC+ajaxFileUpload上传图片 IE浏览器弹下载框问题解决方式
如题,简单记录一下这个问题的解决的方法,导致问题的核心原因是:ajaxfileupload不支持响应头ContentType为application/json的设置.而且IE也不支持这样的格式,而当我 ...
- 搭建java运行环境
安装IDE 集成开发环境(IDE,Integrated Development Environment ) 1.安装jdk,jre(jdk自带jre),记住他们的安装位置. 2.配置环境变量.(JAV ...
- ios 关于动画用法的总结
#import "FirstVC.h" @implementation FirstVC /* 创建xib过程 1 创建xib(名字和类名相同) 2 文件 ...
- UIProgress控件的属性和方法
进度条控件是IOS开发中一个简单的系统控件,使用总结如下: 初始化一个进度条: - (instancetype)initWithProgressViewStyle:(UIProgressViewSty ...
- codeforces 691A A. Fashion in Berland(水题)
题目链接: A. Fashion in Berland 题意: 思路: AC代码: //#include <bits/stdc++.h> #include <iostream> ...
- MyBatis学习 之 四、动态SQL语句
有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空,此时查询出的结果很可能是空的,也许我们需要参数为空时,是查出全部的信息.使用Oracle的序列.mysq ...
- RadioGroup和RadioButton
Activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- python3练习题四
循环 题目: 答案: #!/usr/bin/env python3 #-*- coding:utf-8 -*- L = ['Bart', 'Lisa', 'Adam'] for i in L: pri ...