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