2019 GDUT Rating Contest II : Problem C. Rest Stops
题面:
C. Rest Stops
题目描述:
题目分析:
1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <cmath>
5 #include <set>
6 #include <algorithm>
7 using namespace std;
8 const int maxn = 1e5+5;
9 int l, n, rf, rb;
10
11 struct stop{
12 int x;
13 long long c;
14 };
15
16 stop s[maxn]; //记录休息站的信息
17
18 int max_c[maxn]; //用来记录后面休息站美味值最大的下标
19
20 void test(){
21 cout << endl;
22 for(int i = 0; i < n; i++){
23 cout << s[i].x << " " << s[i].c;
24 cout << endl;
25 }
26
27 cout << endl;
28
29 for(int i = 0; i < n; i++){
30 cout << max_c[i] << endl;
31 }
32 cout << endl;
33 }
34
35 int main(){
36 scanf("%d%d%d%d", &l, &n, &rf, &rb);
37
38 for(int i = 0; i < n; i++){
39 scanf("%d%lld", &s[i].x, &s[i].c);
40 }
41
42 int maxx = 0;
43 int p; //记录上一个美味值最大的休息站的下标
44
45 for(int i = n-1; i >= 0; i--){
46 if(maxx < s[i].c){
47 maxx = s[i].c;
48 p = i; //记录下标
49 }
50 max_c[i] = p; //不断更新从最后面到当前休息站美味值最大的下标
51 }
52 max_c[n] = -1; //结束标记
53
54 //test(); 测试用
55
56 int temp = 0; //上一个停留的休息站的位置
57 long long u, dis, d;
58 long long res = 0;
59 for(int i = 0; i != -1; i = max_c[i+1]){
60 u = max_c[i]; //获得美味值最大的休息站的下标
61 dis = s[u].x - temp;
62
63 d = dis*(rf-rb); //停留时间
64 res += d*s[u].c;
65
66 temp = s[u].x; //记录停留站位置
67 }
68
69 cout << res << endl;
70 return 0;
71 }
2019 GDUT Rating Contest II : Problem C. Rest Stops的更多相关文章
- 2019 GDUT Rating Contest II : Problem F. Teleportation
题面: Problem F. Teleportation Input file: standard input Output file: standard output Time limit: 15 se ...
- 2019 GDUT Rating Contest II : Problem G. Snow Boots
题面: G. Snow Boots Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest II : Problem B. Hoofball
题面: 传送门 B. Hoofball Input file: standard input Output file: standard output Time limit: 5 second Memor ...
- 2019 GDUT Rating Contest III : Problem D. Lemonade Line
题面: D. Lemonade Line Input file: standard input Output file: standard output Time limit: 1 second Memo ...
- 2019 GDUT Rating Contest II : A. Taming the Herd
题面: A. Taming the Herd Input file: standard input Output file: standard output Time limit: 1 second Me ...
- 2019 GDUT Rating Contest I : Problem H. Mixing Milk
题面: H. Mixing Milk Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest I : Problem A. The Bucket List
题面: A. The Bucket List Input file: standard input Output file: standard output Time limit: 1 second Me ...
- 2019 GDUT Rating Contest I : Problem G. Back and Forth
题面: G. Back and Forth Input file: standard input Output file: standard output Time limit: 1 second Mem ...
- 2019 GDUT Rating Contest III : Problem E. Family Tree
题面: E. Family Tree Input file: standard input Output file: standard output Time limit: 1 second Memory ...
随机推荐
- range()函数的使用、while循环、for-in循环等
一.range()函数 用于直接生成一个整数序列 创建range对象的三种方式: (1)range(stop) 创建一个(0,stop)之间的整数序列,步长为1 (2)range(start,s ...
- git branch & git remote branch
git branch & git remote branch $ git branch -h usage: git branch [<options>] [-r | -a] [-- ...
- vuepress config favicon
vuepress config favicon .vuepress/public favicons https://vuepress.vuejs.org/guide/assets.html#publi ...
- JavaScript 高级程序设计 (第4版) 思维导图/脑图 All In One
JavaScript 高级程序设计 (第4版) 思维导图/脑图 All In One JavaScript 高级程序设计 (第4版) 思维导图下载 JavaScript 高级程序设计 (第4版) 脑图 ...
- React.memo All In One
React.memo All In One https://reactjs.org/docs/react-api.html#components React.memo const MyComponen ...
- taro table component
taro table component https://juejin.im/post/5d901696f265da5b926bbcaa https://taro-ext.jd.com/search? ...
- nasm astrstr函数 x86
xxx.asm: %define p1 ebp+8 %define p2 ebp+12 %define p3 ebp+16 section .text global dllmain export as ...
- 画一个PBN大角度飞越转弯保护区
今天出太阳了,尽管街上的行人依旧很少,但心情开始不那么沉闷了.朋友圈里除了关注疫情的最新变化之外,很多人已经开始选择读书或是和家人一起渡过这个最漫长的春节假期.陕西广电网络春节期间所有点播节目一律 ...
- linux DRM 之 GEM 笔记
原文链接:https://www.cnblogs.com/yaongtime/p/14418357.html 在GPU上的各类操作中涉及到多种.多个buffer的使用. 通常我们GPU是通过图像API ...
- 解决ROS及Fast-RTPS安装和使用中raw.githubusercontent.com无法连接的问题
资料参考: https://blog.csdn.net/weixin_44692299/article/details/105869229