P1016 旅行家的预算

单调队列。

再看看单调队列怎么用的。

#include <cstdio>

int n, l, r;
double D, dd, d[9], C, p[9], ans; struct node{
double t, x;
} q[999]; int main() {
scanf("%lf%lf%lf%lf%d", &D, &C, &dd, &p[0], &n); d[0]=0;
for (int i=1; i<=n; ++i) {
scanf("%lf%lf", &d[i], &p[i]);
if (d[i]-d[i-1]>C*dd) {printf("No Solution\n"); return 0; }
}
d[n+1]=D; double now=0.0;
q[++r]=(node){p[0], now=C}, ans+=p[0]*C;
for (int i=1; i<=n+1; ++i) {
double cos=(d[i]-d[i-1])/dd;
while (l<=r && cos>0) {
if (q[l].x>cos) {now-=cos, q[l].x-=cos; break; }
now-=q[l].x, cos-=q[l].x; ++l;
}
if (i==n+1) {
while (l<=r) ans-=q[l].t * q[l].x, ++l; break;
}
while (l<=r && q[r].t>p[i]) {
ans-=q[r].t*q[r].x, now-=q[r].x; --r;
}
ans+=(C-now)*p[i];
q[++r]=(node){p[i], C-now}; now=C;
}
printf("%.2lf\n", ans);
return 0;
}

5 August的更多相关文章

  1. Monthly Income Report – August 2016

    原文链接:https://marcoschwartz.com/monthly-income-report-august-2016/ Every month, I publish a report of ...

  2. [ZZ]Sign Up for the First-Ever Appium Roadshow on August 20th in New York City

    http://sauceio.com/index.php/2014/07/appium-roadshow-nyc/?utm_source=feedly&utm_reader=feedly&am ...

  3. 浙大月赛ZOJ Monthly, August 2014

    Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...

  4. [转载]ECMA-262 6th Edition / Draft August 24, 2014 Draft ECMAScript Language Specification

    http://people.mozilla.org/~jorendorff/es6-draft.html#sec-23.4 Draft Report Errors and Issues at: htt ...

  5. 135 - ZOJ Monthly, August 2014

    135 - ZOJ Monthly, August 2014 A:构造问题,推断序列奇偶性.非常easy发现最小值不是1就是0.最大值不是n就是n - 1,注意细节去构造就可以 E:dp.dp[i][ ...

  6. git -remote: Support for password authentication was removed on August 13, 2021

    克隆代码时,报错: Support for password authentication was removed on August 13, 2021. Please use a personal ...

  7. August 31st 2016 Week 36th Tuesday

    A friend without faults will never be found. 没有缺点的朋友是永远找不到的. You can't find a friends without faults ...

  8. August 30th 2016 Week 36th Tuesday

    If you keep on believing, the dreams that you wish will come true. 如果你坚定信念,就能梦想成真. I always believe ...

  9. August 29th 2016 Week 36th Monday

    Every has the capital to dream. 每个人都有做梦的本钱. Your vision, our mission. That is an advertisment of UMo ...

  10. August 28th 2016 Week 36th Sunday

    What doesn't kill you makes you stronger. 那些没有彻底击败你的东西只会让你更强大. Where there is life, there is hope, a ...

随机推荐

  1. rpm --qf 命令

    1. 环境准备: sudo apt-get install rpm (Ubuntu系统) wget ftp://rpmfind.net/linux/fedora-secondary/developme ...

  2. uni-app 云打包证书生成笔记

    一.android 云打包生成证书 1.jdk和jre安装,配置环境 2.在 C:\Users\Administrator\.android 文件夹下执行:keytool -genkey -alias ...

  3. Xmanger远程连接Centos7(成功配置)

    参考1:https://blog.csdn.net/wuzhimang/article/details/51523867 参考2:https://blog.csdn.net/name_kongkong ...

  4. CET-6 分频周计划生词筛选(番外篇:百词斩)

    点我阅读 番外-百词斩 2016.09.18 12:00pm transverse counterpart accessory cult gorgeous sediment assimilate st ...

  5. Java IO(3)

    字符流相关 字符流基本上可以类比字节流 只不过是将字节流的byte 换为char. 最根本的两个类是Reader以及Writer Reader的子类有:BufferedReader, CharArra ...

  6. Google File System 论文阅读笔记

    核心目标:Google File System是一个面向密集应用的,可伸缩的大规模分布式文件系统.GFS运行在廉价的设备上,提供给了灾难冗余的能力,为大量客户机提供了高性能的服务. 1.一系列前提 G ...

  7. numpy.meshgrid的理解以及3D曲面图绘制(梯度下降法实现过程)

    相关概念: 1.x向量和y向量 import numpy as np import matplotlib.pyplot as plt x = np.array([[0,1,2,3], [0,0,0,0 ...

  8. [Linux] 005 Linux 常见目录的作用及一些注意事项

    1. Linux 常见目录及其作用 目录名 作用 /bin/ 存放系统命令的目录普通用户各超级用户都可以执行放在 /bin 下的命令在单用户模式下也可以执行 /sbin/ 保存和系统环境相关的命令只有 ...

  9. JS的两种函数声明方式的区别

    ---恢复内容开始--- js中常见的两种函数声明方式如下: // 函数表达式 var f = function() { console.log(1); } // 直接声明 function f () ...

  10. Python入门习题7.分别统计输入各类字符个数

    例7.用户从键盘输入一行字符,编写一个程序,统计并输出其中的英文字符(包括中文字符).数字.空格和其他字符个数. #字符数统计.py Str = input('请输入一行字符:') alpha = 0 ...