8VC Venture Cup 2016 - Final Round (Div2) E
贪心。当前位置满油可达的gas station中,如果有比它小的,则加油至第一个比他小的。没有,则加满油,先到达这些station中最小的。注意数的范围即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long using namespace std; const int MAXN = 200050; int d, n, m; int gp[MAXN], gpz[MAXN];
int fl[MAXN]; struct gas{
int pos, price;
}g[MAXN]; bool cmp(gas a, gas b){
if(a.pos < b.pos) return true;
return false;
} int main(){
scanf("%d%d%d", &d, &n, &m); gp[0] = 0, gpz[0] = 1e7;
for(int i = 1; i <= m; i++){
scanf("%d%d", &g[i].pos, &g[i].price);
} sort(g + 1, g + 1 + m, cmp); for(int i = 1; i <= m; i++){
gp[i] = g[i].pos, gpz[i] = g[i].price;
} gp[m + 1] = d, gpz[m + 1] = 0; /*
for(int i = 0; i<= m + 1; i++)
cout <<gp[i] <<" "<< gpz[i] << endl;
cout << endl;
*/
int mindist = -1; for(int i = 0; i <= m; i++){
mindist = max(mindist, gp[i + 1] - gp[i]);
} // cout << mindist << endl; if(mindist > n){
puts("-1");
return 0;
} if(d <= n){
puts("0");
return 0;
} for(int i = m; i >= 0; i--){
if(gpz[i + 1] <= gpz[i]){
fl[i] = i + 1;
}
else {
int tmp = i + 1;
while(gpz[fl[tmp]] > gpz[i]){
tmp = fl[tmp];
}
fl[i] = fl[tmp];
}
}
/*
for(int i = 0; i<= m; i++){
cout << fl[i] <<" ";
}
cout << endl; */ LL ans = 0;
int liter = n; for(int l = 0; l < m+ 1; ){
if(gp[fl[l]] - gp[l] > n){
ans += (LL)(n - liter) * gpz[l];
int tmp = l + 1;
while(gp[fl[tmp]] - gp[l] <= n){
tmp = fl[tmp];
}
liter = n - (gp[tmp] - gp[l]);
l = tmp;
}
else{
int tmp = fl[l];
if(tmp == m + 1){
ans += (LL)(d - gp[l] - liter) * gpz[l];
break;
}
else{
if(gp[tmp] - gp[l] <= liter){
liter -= gp[tmp] - gp[l];
}
else{
ans += (LL)(gp[tmp] - gp[l] - liter)*gpz[l];
liter = 0;
}
l = tmp;
}
}
// cout << l << endl;
// system("pause");
}
cout << ans << endl; }
8VC Venture Cup 2016 - Final Round (Div2) E的更多相关文章
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)
暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(S ...
- 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp
E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A
A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 8VC Venture Cup 2016 - Final Round D. Preorder Test 二分 树形dp
Preorder Test 题目连接: http://www.codeforces.com/contest/627/problem/D Description For his computer sci ...
- 8VC Venture Cup 2016 - Final Round C. Package Delivery 优先队列
C. Package Delivery 题目连接: http://www.codeforces.com/contest/627/problem/C Description Johnny drives ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) D. Factory Repairs 树状数组
D. Factory Repairs 题目连接: http://www.codeforces.com/contest/635/problem/D Description A factory produ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学
C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题
B. sland Puzzle 题目连接: http://www.codeforces.com/contest/635/problem/B Description A remote island ch ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A. Orchestra 水题
A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orches ...
随机推荐
- Apache与IIS端口冲突解决方法
在安装Apache或者php集成环境包是经常会遇到Apache的80端口被占用导致无法正常启动Apache. Win7可以通过如下方法解决(如果坚持要使用80端口的话): 1.打开"控制面板 ...
- pdf 使用模板下载
//根据模板下载模板 /** * * 政策5-8条的创建的pdf的模板 */public String createPdfCashTemplate(PdfCashParam pdfCashParam) ...
- laravel 只有/login路由403,如何解决
链接/login自动转跳到/login/导致找不到 /public/login/ 目录导致403; 将路由中\login改为\login1访问正常,但login依然403,而不是未找到路由 链接/lo ...
- 導出Excel方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- 使用python划分数据集
无论是训练机器学习或是深度学习,第一步当然是先划分数据集啦,今天小白整理了一些划分数据集的方法,希望大佬们多多指教啊,嘻嘻~ 首先看一下数据集的样子,flower_data文件夹下有四个文件夹,每个文 ...
- viewport 640宽的做法 针对iphone和安卓单独设置
<!DOCTYPE html> <html lang="ch"> <head> <meta charset="utf-8&quo ...
- 实训day01 python基础
一.编程语言 编程语言:可以被计算机所识别的表达方式. 编程:程序员通过编程语言将自己的想法编写出来,产生的结果就是包含字符的文件. 其中,只有程序在运行时,其中的字符才有特定的语法意义. 二.计算机 ...
- JS判断字符串包含的方法
本文实例讲述了JS判断字符串包含的方法.分享给大家供大家参考.具体如下: 1. 例子: 1 2 3 4 5 6 7 8 var tempStr = "tempText" ; var ...
- 2 SQL 查询基础
2 查询基础 2-1 SELECT语句基础 通过SELECT语句查询并选取必要数据的过程称为匹配查询或查询(query). 子句是SQL语句的组成要素,是以SELECT或者FROM等作为起始的短语. ...
- linux文件及目录的权限管理
一.文件的权限 1.文件权限的查看 命令:ls -l 可以使用ll命令代替 ls -l 2.ls -l 所包含的信息 (1)权限信息 (-rw-r--r-- ) 一共有10位 a.第一位:表示文件信息 ...