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 ... 
随机推荐
- 4.安装fluentd用于收集集群内部应用日志
			作者 微信:tangy8080 电子邮箱:914661180@qq.com 更新时间:2019-06-13 11:02:14 星期四 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程 ... 
- 按层次顺序创建二叉树;判断BST
			https://github.com/TouwaErioH/subjects/tree/master/C%2B%2B/PA2 BST 假设已经给定树节点的结构不可修改. 然后输入是按照层次顺序 怎样创 ... 
- ajax和comet
			一,XMLHttpRequest对象 IE5是最早引入XHR对象的浏览器,XHR对象是通过MSXML库中的一个ActiveX对象实现的 使用MSXML库中的XHR对象,编写一个函数如下 functio ... 
- mybatis(一)常见ORM框架及JDBC操作工具类
			转载:https://www.cnblogs.com/wuzhenzhao/p/11075569.html 在Java 程序里面去连接数据库,最原始的办法是使用JDBC 的API.我们先来回顾一下 ... 
- mysql(一)--mysql架构和执行流程
			1. 一条查询 SQL 语句是如何执行的? 我们的程序或者工具要操作数据库,第一步要做什么事情? 跟数据库建立连接. 1.1. 通信协议 首先,MySQL 必须要运行一个服务,监听默认的 3306 ... 
- Dos简单命令及CMD打开方式
			打开CMD方式 开始+系统+命令提示符 WIN健+R 输入cmd打开控制台(推荐使用) 在任意文件夹下面,按住shift+鼠标右击,进入powershell 资源管理器的地址栏路径最前面+cmd+空格 ... 
- SASS CSS3 koala
			CSS with superpowers Sass: Syntactically Awesome Style Sheets http://sass-lang.com/ Sass is the most ... 
- node os env reader
			node os env reader node-os-env-reader.js #!/usr/bin/env node "use strict"; /** * * @author ... 
- vscode & ignore .idea
			vscode & ignore .idea settings.json .vscode & ignore .idea // 将设置放入此文件中以覆盖默认设置 { "files ... 
- skills share & free videos
			skills share & free videos 技术分享 & 免费视频 https://www.infoq.cn/video/list WebAssembly https://w ... 
