贪心。注意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. Oracle体系结构总览

    第一篇 Oracle架构总览 先让我们来看一张图   这张就是Oracle 9i的架构全图.看上去,很繁杂.是的,是这样的.现在让我们来梳理一下: 一.数据库.表空间.数据文件 1.数据库 数据库是数 ...

  2. 基于 python 的接口测试框架

    项目背景 公司内部的软件采用B/S架构,管理实验室数据,实现数据的存储和分析统计.大部分是数据的增删改查,由于还在开发阶段,所以UI界面的变化非常快,之前尝试过用python+selenium进行UI ...

  3. 使用Recast.AI创建具有人工智能的聊天机器人

    很多SAP顾问朋友们对于人工智能/机器学习这个话题非常感兴趣,也在不断思考如何将这种新技术和SAP传统产品相结合.Jerry之前的微信公众号文章C4C和微信集成系列教程曾经介绍了Partner如何利用 ...

  4. Visual Odometry

    http://www.cvlibs.net/datasets/kitti/eval_odometry.php

  5. js模块化入门与commonjs解析与应用

    JS模块化的基本原理 commonjs规范 commonjs在前端模块化中的基本使用 AMD与CMD规范剖析博客链接 一.JS模块化基本原理 在JS没有提出来模块化的时候,开发JS项目比较简单,同时也 ...

  6. CentOS7.6 静态IP配置

    1:选中安装好的虚拟机,点击“编辑”,然后选择“虚拟网络编辑器(N…)”,如下图所示: 2:选择桥接模式,在桥接到指定的本地网卡即可."确定"保存 3:选中虚拟机,右击虚拟机,选择 ...

  7. Shell数值比较

    Shell数值比较 比较 描述 n1 -eq n2 检查n1是否与n2相等 n1 -ge n2 检查n1是否大于或等于n2 n1 -gt n2 检查n1是否大于n2 n1 -le n2 检查n1是否小 ...

  8. IO之Object流举例

    import java.io.*; public class TestObjectIO { public static void main(String args[]) throws Exceptio ...

  9. LeetCode(20)Valid Parentheses

    题目 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the i ...

  10. ASP.NET MVC如何在页面加载完成后ajax异步刷新

    背景:之前已写过两篇有关Ajax的随笔,这一篇是单独针对在页面加载完成的Ajax操作.比如说打开学生列表页面,先加载页面,然后以Ajax的方式,从数据库中检索相应的学生信息,给浏览者更好的体验. 简单 ...