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 ...
随机推荐
- python sort() sorted()的区别
sorted不保存 sort保存:
- 关于string类中find函数的讲解
以下所讲的所有的string查找函数,都有唯一的返回类型,那就是size_type,即一个无符号整数(按打印出来的算).若查找成功,返回按查找规则找到的第一个字符或子串的位置:若查找失败,返回npos ...
- ASP.NET Core 中间件(Middleware)(一)
本文主要目标:记录Middleware的运行原理流程,并绘制流程图. 目录结构: 1.运行环境 2.Demo实践 3.源码追踪 4.AspnetCore内置middleware 一.运行环境 Visu ...
- npm clear folder
npm clear folder rm -rf rimraf rmrf & clear build / dist folder caches https://www.npmjs.com/pac ...
- bob and brad physical therapy knee exercise
bob and brad physical therapy knee exercise 鲍勃和布拉德物理治疗膝关节运动 https://bobandbrad.com/ youtube https:// ...
- npm & app-node-env
npm & app-node-env $ npm i -g app-node-env # OR $ yarn global add app-node-env demo $ ane env=ap ...
- CORS & OPTIONS & preflight request
CORS & OPTIONS preflight request CORS 原理 CORS跨域的原理实际上是浏览器与服务器通过一些HTTP协议头来做一些约定和限制 OPTIONS 应用场景 h ...
- vue2.0用法以及环境配置
一.配置环境搭建 1.安装node.js (可以去官网看) 2.安装git (推荐看廖雪峰文章,点击查看) 3.安装vue: cmd:npm install vue //最新稳定版本 npm inst ...
- 打造NGK生态星空计划,高倍币VAST即将震撼上线!
援引华盛顿邮报.彭博社.路透社以及CNN等知名媒体的报道,NGK官方近日宣布,为了完善NGK生态星空计划,NGK官方近日即将推出SPC的子币VAST,以鼓励更多的生态建设者参与. NGK官方相关负责人 ...
- PAA养老房产:以情怀打造精细化服务
养老服务工作需要从业者具备尊老.爱老.敬老的职业道德,这种职业道德的培养非一朝一夕可锻造,而是需要长年累月.一点一滴的渗透和养成.PAUL ADAMS ARCHITECT(以下简称PAA)(公司编号: ...