PAT (Advanced Level) 1033. To Fill or Not to Fill (25)
贪心。注意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)的更多相关文章
- 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 ...
- 【PAT Advanced Level】1006. Sign In and Sign Out (25)
关键在于清空字符数组和使用scanf进行输入 #include <stdio.h> #include <string.h> #include <fstream> # ...
- PAT (Advanced Level) 1043. Is It a Binary Search Tree (25)
简单题.构造出二叉搜索树,然后check一下. #include<stdio.h> #include<algorithm> using namespace std; +; st ...
- 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 ...
- 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, ...
- 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 ...
- PAT (Advanced Level) Practice 1001-1005
PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...
- PAT (Advanced Level) Practice(更新中)
Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...
- PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
随机推荐
- java将一个List赋值给另一个List的4种方法
编辑 删除 声明:ArrayList a, 仅仅只是声明了一个list变量,其未来作用相当于C++中的引用变量,亦或者相当于一个对象块的索引,但并未为其分配具体的完整的对象所需要的内存空间,其所分配的 ...
- 诊断Java代码中常见的数据库性能热点问题应该这么做!
“你的Java应用程序的性能是怎样诊断和优化的?不妨看看这两位西医的方子.如果你有更好疗效的药方,也欢迎在评论区告诉我们. 当我在帮助一些开发者或架构师分析及优化Java应用程序的性能时,关键往往不在 ...
- 洛谷 P2680 运输计划
题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n-1 条航道连通了 L 国的所有星球. 小 P 掌管一家 ...
- 洛谷 P1802 5倍经验日
题目背景 现在乐斗有活动了!每打一个人可以获得5倍经验!absi2011却无奈的看着那一些比他等级高的好友,想着能否把他们干掉.干掉能拿不少经验的. 题目描述 现在absi2011拿出了x个迷你装药物 ...
- 千万千万不要运行的 Linux 命令
文中列出的命令绝对不可以运行,即使你觉得很好奇也不行,除非你是在虚拟机上运行(出现问题你可以还原),因为它们会实实在在的破坏你的系统.所以不在root等高级管理权限下执行命令是很好的习惯. 早晚有一天 ...
- (转)为Spring集成的Hibernate配置二级缓存
http://blog.csdn.net/yerenyuan_pku/article/details/52896195 前面我们已经集成了Spring4.2.5+Hibernate4.3.11+Str ...
- Python3简明教程(二)—— 变量和数据类型
关键字和标识符 下列的标识符是Python3的关键字,并且不能用于通常的标识符.关键字必须严格按照下面的拼写: False def if raise None del import return Tr ...
- END - 提交当前的事务
SYNOPSIS END [ WORK | TRANSACTION ] DESCRIPTION 描述 END END 提交当前事务. 所有当前事务做的修改都可被其它事务看到并且保证在发生崩溃的情况下的 ...
- 在Vue中遇到的各种坑 及性能提升
Vue: (1) 没有再模板里引用data数据,会不会引起update.beforeUpdate生命周期函数的执行? 不会 (2)组件改成异步 (3)v-once (4)如果不用template ...
- upload 上传 加token 在 :headers='headers' 注意 不要直接写$refs.upload.headers = {} 这样vue会警告 修改组件内部变量
upload 上传 加token 在 :headers='headers' 注意 不要直接写$refs.upload.headers = {} 这样vue会警告 修改组件内部变量 <Upload ...