贪心。注意x=0处没有加油站的情况。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; struct X
{
double cost, x, v;
int id;
}s[ + ];
double C, D, P;
double len;
int n; bool f(double a, double b)
{
if (fabs(a - b)<1e-) return ;
return ;
} struct Y
{
int id;
double cost, x, v;
Y(int ID, double COST, double X,double V)
{
id = ID;
cost = COST;
x = X;
v = V;
}
bool operator < (const Y &a) const {
if (f(cost, a.cost)) return x>a.x;
return cost>a.cost;
}
}; bool cmp(const X&a, const X&b) { return a.x<b.x; } bool FAIL()
{
len = ;
if (s[].x > ) return ;
for (int i = ; i < n; i++)
{
len = s[i].x + P*C;
if (len < s[i + ].x) return ;
}
return ;
} int main()
{
scanf("%lf%lf%lf%d", &C, &D, &P, &n);
for (int i = ; i <= n; i++)
{
scanf("%lf%lf", &s[i].cost, &s[i].x);
s[i].v = ;
}
sort(s + , s + + n, cmp);
if (s[n].x<D) n++, s[n].x = D;
for (int i = ; i <= n; i++) s[i].id = i; if (FAIL()) printf("The maximum travel distance = %.2lf\n", len);
else
{
double sum = , ans = ;
int p = ; priority_queue<Y>Q;
Q.push(Y(, s[].cost, s[].x, )); for (int i = ; i <= n; i++)
{
double d = s[i].x - s[i - ].x;
double need = d / P; while ()
{
if (f(need, )) break;
while ()
{
Y head = Q.top(); Q.pop();
if (head.id < p) continue;
else if (f(s[head.id].v, C)) continue;
else
{
p = head.id;
double h = min(need, C - s[p].v);
need = need - h;
sum = sum + h;
s[p].v = sum - s[p].x / P;
ans = ans + s[p].cost*h;
Q.push(head);
break;
}
}
} Q.push(Y(i, s[i].cost, s[i].x, ));
}
printf("%.2lf\n", ans);
}
return ;
}

PAT (Advanced Level) 1033. To Fill or Not to Fill (25)的更多相关文章

  1. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...

  2. 【PAT Advanced Level】1006. Sign In and Sign Out (25)

    关键在于清空字符数组和使用scanf进行输入 #include <stdio.h> #include <string.h> #include <fstream> # ...

  3. PAT (Advanced Level) 1043. Is It a Binary Search Tree (25)

    简单题.构造出二叉搜索树,然后check一下. #include<stdio.h> #include<algorithm> using namespace std; +; st ...

  4. PAT (Advanced Level) Practise - 1097. Deduplication on a Linked List (25)

    http://www.patest.cn/contests/pat-a-practise/1097 Given a singly linked list L with integer keys, yo ...

  5. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) (排序)

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  6. PAT (Advanced Level) Practice 1002 A+B for Polynomials 分数 25

    This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each ...

  7. PAT (Advanced Level) Practice 1001-1005

    PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...

  8. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

  9. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

随机推荐

  1. js中json处理总结之JSON.parse

    踩过的坑都将成为路上的风景.队友在cookie中已存以下值: address_info {"address_name":"人民大会堂","...lng ...

  2. HDU 5414 CRB and String (字符串,模拟)

    题意:给两个字符串s和t,如果能插入一些字符使得s=t,则输出yes,否则输出no.插入规则:在s中选定一个字符c,可以在其后面插入一个字符k,只要k!=c即可. 思路:特殊的情况就是s和t的最长相同 ...

  3. 原创:mysql下载 实战 最强最全的无脑白痴版 给小白的爱

  4. iview tabs里面放入 i-switch 注意slot不是写在 props里面

    iview tabs里面放入 i-switch 注意slot不是写在 props里面 <Tabs value="name1"> <TabPane :label=& ...

  5. Vue 2.0 右键菜单组件 Vue Context Menu

    Vue 2.0 右键菜单组件 Vue Context Menu https://juejin.im/entry/5976d14751882507db6e839c

  6. Python基础3 函数 变量 递归 -DAY3

    本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数 温故知新 1. 集合 主要作用: 去重 关系测 ...

  7. python基础一 day9 函数升阶(1)

    函数 可读性强 复用性强def 函数名(): 函数体 return 返回值所有的函数 只定义不调用就一定不执行 先定义后调用 函数名() #不接收返回值返回值 = 函数名() #接收返回值 返回值 没 ...

  8. python基础一 day3 列表方法

    ls=['a','b','c','d','a','b','c','d']lst=['e','f','g','h']# 增加# ls.append('a') 将元素a添加至列表ls的尾部# ls.ext ...

  9. Microsoft Windows Server 系统基本配置

    Microsoft Windows Server 系统基本配置 环境基本配置 桌面和显示属性 更新服务器名称 更新用户密码 创建密码重置盘 设置网络类型 TCP/IP设置 ping和ipconfig命 ...

  10. 【转】解决WPF图片模糊最佳方法(绑定PixelWidth与PixelHeight)

    解决WPF图片模糊最佳方法(绑定PixelWidth与PixelHeight) 转载自:http://www.360doc.com/content/13/1126/09/10504424_332211 ...