链接:https://codeforces.com/contest/1130/problem/D1

题意:

给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果。

求从每个位置开车的最小的时间。

思路:

vector记录每个位置运送完拥有糖果的时间消耗,为糖果数-1 * n 加上消耗最少时间的糖果。

对每个起点进行运算,取所有点中的最大值。

代码:

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long LL;
  6. const int MAXN = 200 + 10;
  7.  
  8. vector<int> station[MAXN];
  9. int train[MAXN];
  10.  
  11. int main()
  12. {
  13. int n, m;
  14. int s, c;
  15. scanf("%d%d", &n, &m);
  16. for (int i = 1;i <= m;i++)
  17. {
  18. scanf("%d%d", &s, &c);
  19. int cost;
  20. if (s <= c)
  21. cost = c - s;
  22. else
  23. cost = n - (s - c);
  24. station[s].push_back(cost);
  25. }
  26. for (int i = 1;i <= n;i++)
  27. sort(station[i].begin(), station[i].end());
  28. for (int i = 1;i <= n;i++)
  29. {
  30. int res = -1;
  31. for (int j = 1;j <= n;j++)
  32. {
  33. if (!station[j].size())
  34. continue;
  35. int cost;
  36. if (i <= j)
  37. cost = j - i;
  38. else
  39. cost = n - (i - j);
  40. int k = station[j].size() - 1;
  41. cost += k * n;
  42. cost += station[j][0];
  43. res = max(res, cost);
  44. }
  45. printf("%d ", res);
  46. }
  47.  
  48. return 0;
  49. }

  

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. centos下部署项目问题

    最近写了商品管理的后台完成了一部分,用node+koa+mongodb搭建,现在想部署到自己的服务器上,部署的过程中遇到了一些坑.首先就是各种环境的搭建,搭建好了之后要把后台的代码传到服务器上运行,运 ...

  2. Spyder的汉化

    我准备写下spyder的汉化问题:对于英文大佬,从来没得汉化问题,但是对于新手和英语差的来说,汉化还是有必要,至少用汉化过得软件能快速掌握软件等.后期会用软件了在慢慢习惯英文也不迟...哈哈哈哈.本文 ...

  3. 在vs2005中添加lib库的方法

    方法一:在用到lib的地方加上  //强烈推荐这种方法.#pragma    comment(lib,"libname.lib") 方法二:     点击菜单命令 “项目/属性”, ...

  4. sanic官方文档解析之streaming(流动,滚动)和class_based_views(CBV的写法)

    1,streaming(流媒体) 1.1请求流媒体 Sanic允许你通过流媒体携带请求数据,如下,当请求结束await request.stream.read()就会返回None,仅仅只有post请求 ...

  5. Golang 现有的哲学中,要求你尽量手工处理所有的错误返回

    更优雅的 Golang 错误处理 - Go语言中文网 - Golang中文社区 https://studygolang.com/articles/9407

  6. webservice client setTimeOut

    一:eclipse生成的client,基于axis client_sub.getOptions().setTimeOutInMilliSeconds(1000*60); client_sub表示一个客 ...

  7. poj 3585 Accumulation Degree(二次扫描和换根法)

    Accumulation Degree 大致题意:有一棵流量树,它的每一条边都有一个正流量,树上所有度数为一的节点都是出口,相应的树上每一个节点都有一个权值,它表示从这个节点向其他出口可以输送的最大总 ...

  8. js 原型继承和class继承

    摘自http://www.liaoxuefeng.com/ 在传统的基于Class的语言如Java.C++中,继承的本质是扩展一个已有的Class,并生成新的Subclass. 由于这类语言严格区分类 ...

  9. 关于谷歌浏览器默认字体12px的解决方案

    1. * Chrome 中文界面下默认会将小于 12px 的文本强制按照 12px 显示, 可通过加入 CSS 属性 -webkit-text-size-adjust: none; 解决. 超链接访问 ...

  10. FZU2150 Fire Game —— BFS

    题目链接:https://vjudge.net/problem/FZU-2150 Problem 2150 Fire Game Accept: 2702    Submit: 9240 Time Li ...