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: ...
随机推荐
- 微信小程序组件解读和分析:一、view(视图容器 )
view组件说明: 视图容器 跟HTML代码中的DIV一样,可以包裹其他的组件,也可以被包裹在其他的组件内部.用起来比较自由随意,没有固定的结构. view组件的用法: 示例项目的wxml ...
- Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied : Permission denied
Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied : Permission den ...
- codevs 1219 骑士游历 1997年
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 设有一个n*m的棋盘(2≤n≤50,2≤m≤50),如下图,在棋盘上有一个中国象 ...
- Unity c# 状态机的简单入门
状态机模式在unity中作用是非常大的,可以实现角色的移动和场景的跳转,包括一些动画的播放,在很多unity框架中也是很常见的,发散思维广阔,下面是简单的状态机的实现,有注释 using System ...
- Eclipse Code Recommenders 自动补全(联想)神器
Eclipse Code Recommenders 可以在eclipse市场中下载.自动补全.模糊匹配.非常有用!
- CFNetwork framework
iphone包含了很多框架和库,从底层的套接字到不同层次的封装,可以方便地给程序添加网络功能. (1)BSD套接字.最底层的套接字,这是Unix网络开发常用的API.如果从其他系统移植程序,而程序用的 ...
- 编码&解码
编码与解码首先,明确一点,计算机中存储的信息都是二进制的 编码/解码本质上是一种映射(对应关系):比如‘a’用ascii编码则是65,计算机中存储的就是00110101,但是显示的时候不能显示0011 ...
- 条款33:避免遮掩继承而来的名称(Avoiding hiding inherited names)
NOTE: 1.derived classes 内的名称会遮掩base classes内的名称.在public继承下从来没有人希望如此. 2.为了让被遮掩的名称再见天日,可使用using 声明方式或转 ...
- Windows使用Nginx+ffmpeg搭建RTMP服务器
简介Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.nginx-rmtp-module是Nginx服务器的流媒体插件.nginx通过rtmp模块提供r ...
- python中的函数的分类
函数的种类 传参的基本要求 默认参数 *args 关键字参数 **kwargs 普通函数 带参数 默认参数 def text(a,b=2) print("haha") print( ...