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 ...
随机推荐
- 6.Header交换机之模拟验证用户身份
标题 : 6.Header交换机之模拟验证用户身份 目录 : RabbitMQ 序号 : 6 var channel = connection.CreateModel(); //设置服务质量 ch ...
- leetcode11 盛水容器 贪心
这道题,总感觉做过... 先理解题意,何为容器 容器 要求水面高度相同 于是体积就是长方形,高度有两块较高板的低板决定,宽度由两块板间距离决定. 考虑当前最优解,就贪心 从两边开始向内,若能使得体积变 ...
- QXDM和QCAT软件使用指南
一.传送门 链接:https://pan.baidu.com/s/1i55YXnf 密码:v6nw 二.QXDM,QPST和QCAT的简单说明 QXDM,QPST和QCAT是Qualcomm高通公司针 ...
- scu-4440 rectangle (非原创)
Rectangle frog has a piece of paper divided into nn rows and mm columns. Today, she would like to dr ...
- Leetcode(868)-二进制间距
给定一个正整数 N,找到并返回 N 的二进制表示中两个连续的 1 之间的最长距离. 如果没有两个连续的 1,返回 0 . 示例 1: 输入:22 输出:2 解释: 22 的二进制是 0b10110 . ...
- 深入 Python 解释器源码,我终于搞明白了字符串驻留的原理!
英文:https://arpitbhayani.me/blogs/string-interning 作者:arpit 译者:豌豆花下猫("Python猫"公众号作者) 声明:本翻译 ...
- open an iOS simulator from the terminal
open an iOS simulator from the terminal # simulator $ open -a Simulator flutter https://flutter.dev/ ...
- 旅游玩乐 业务组件 UI 交互
旅游玩乐 业务组件 UI 交互 旅游业务组件 ctrip PC web https://piao.ctrip.com/dest/t4651499.html M web https://m.ctrip. ...
- taro alipay
taro alipay 开发指南 https://nervjs.github.io/taro/docs/GETTING-STARTED.html#支付宝小程序 { "name": ...
- Flutter 模拟youtube快进icon
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends State ...