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;
}

最新文章

  1. 洛谷P1808 单词分类
  2. mysql中常用的字符串函数
  3. LINUX VI 常用命令
  4. 高级Javascript调试——console.table()
  5. 题目:打印出所有的 &quot;水仙花数 &quot;,所谓 &quot;水仙花数 &quot;是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个 &quot;水仙花 数 &quot;,因为153=1的三次方+5的三次方+3的三次方。
  6. import numpy 和 from numpy import * 的区别
  7. WPF 之 鼠标双击事件
  8. 我被eclipse的tomcat坑的经历
  9. xxx couldn&#39;t be loaded because it has not been added to the build settings.
  10. DLL入门浅析(4)——从DLL中导出类
  11. 【大话QT之十七】Jenkins介绍及安装使用文档(与Git集成)
  12. 给Activity切换加入动画
  13. 第四十一节,xml处理模块
  14. Dom2016/4/20
  15. 痞子衡嵌入式:ARM Cortex-M文件那些事(4)- 可重定向文件(.o/.a)
  16. tmp目录自动清除和tmpwatch命令
  17. T-SQL 局部变量和全局变量
  18. ISO GPS定位,坐标转换以及如何显示
  19. Struts2,Spring,Hibernate框架的优缺点
  20. java链接mysql 中文乱码

热门文章

  1. C#的一般处理程序中Cookie的写入、读取、清除
  2. Object.watch
  3. Action 分离
  4. 16、NumPy ——字节交换
  5. python 分析 知乎粉丝数据
  6. Ajax爬取百度图片
  7. 【记录】mysql查询语句对于为null和为空字符串给出特定值处理
  8. shell判断/bin目录下date文件是否存在
  9. 93-基于ATOM E3825的3U PXIe 主板控制器
  10. [react-native]react-native填坑笔记