贪心。注意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. laravel如何查找门脸及注入类方法

    门脸模式 通过 config/app.php 查看别名对应类名 Illuminate\Support\Facades\Log ,查看 LoggerInterface 类文件,得:命名空间+接口名 Ps ...

  2. Jmeter官网文档翻译

    Jmeter目录 入门 1.0概述 测试计划建设 负载测试运行 负载测试分析 开始吧 1.1要求 1.1.1 Java版本 1.1.2操作系统 1.2可选 1.2.1 Java编译器 1.2.2 SA ...

  3. 洛谷 P1726 上白泽慧音

    题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...

  4. HTTP 200 OK和HTTP 304 Not modified的由来

    这两个字段都和HTTP协议的缓存控制相关. 浏览器缓存机制是通过HTTP协议Header里的Cache-Control(或Expires)和Last-Modified(或 Etag)等字段来实现. 这 ...

  5. (转)Spring4.2.5+Hibernate4.3.11+Struts2.3.24整合开发

    http://blog.csdn.net/yerenyuan_pku/article/details/52902851 前面我们已经学会了Spring4.2.5+Hibernate4.3.11+Str ...

  6. final关键字所修饰的类有什么特点

    Java关键字final有“这是无法改变的”或者“终态的”含义,它可以修饰非抽象类.非抽象类成员方法和变量. final类不能被继承,没有子类,final类中的方法默认是final的. final方法 ...

  7. Win10 启动64位IE浏览器——修改注册表方法

    修改注册表[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]下的: "TabProcGrowth"=DWOR ...

  8. 1、C编程预备计算机知识

    一.数据类型 基本数据类型 1.整数 整形 -- int -- 4 短整型 -- short int -- 2 长整型 -- long int --8 2.浮点数(实数) 单精度浮点数 -- floa ...

  9. mysql中ibatis的limit动态传参

    param.put("pageNo",pageNo);   param.put("pageSize",pageSize); sqlMap中的用法 limit $ ...

  10. Fortran中常用函数列表

    Y=INT(X) 转换为整数 ALL(所有型态) INTEGER Y=REAL(X) 转换为实数 INTEGER REAL Y=DREAL(X) 取复数实部(倍精度) COMPLEX*16 REAL* ...