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 ...
随机推荐
- Leetcode(337)-打家劫舍III
小偷又发现一个新的可行窃的地点. 这个地区只有一个入口,称为"根". 除了根部之外,每栋房子有且只有一个父房子. 一番侦察之后,聪明的小偷意识到"这个地方的所有房屋形成了 ...
- Leetcode(13)-罗马数字转整数
罗马数字包含以下七种字符:I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即为两个并列 ...
- 计组CPU设计实验关键材料和关键设计
我记得这是2016春季学期搞得,参考和学习了很多别人的东西,这里小小的总结一下,逻辑性还不是太强,还需要好好整理 首先是指令集 CPU架构 外部接线架构 指令格式 机器状态自动机 这部分忘了,汗 这部 ...
- matplotlib 图标显示中文
matplotlib 显示中文 Method_1: # 添上: plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.rcPara ...
- CDN 工作原理剖析
CDN 工作原理剖析 CDN / Content Delivery Network / 内容分发网络 https://www.cloudflare.com/zh-cn/learning/cdn/wha ...
- JavaScript Weekly
JavaScript Weekly 技术订阅 https://javascriptweekly.com/issues/489 WebGL https://xem.github.io/articles/ ...
- npm install 原理
npm install 原理 https://docs.npmjs.com/about-npm/ npm consists of three distinct components: the webs ...
- Chrome 80 & SameSite & cookie
Chrome 80 & SameSite & cookie chrome://settings/help https://developers.google.com/web/updat ...
- Google can't be accessed again, today is shit day
Google can't be accessed again, today is shit day 2019.11.28 12:00~20:56 holy shit (pile of poop) Go ...
- c++ 动态设置函数
#include <iostream> #include <Windows.h> #include <TlHelp32.h> using namespace std ...