博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【文文殿下】 [USACO08MAR]土地征用 题解
阅读量:6955 次
发布时间:2019-06-27

本文共 1922 字,大约阅读时间需要 6 分钟。

题解

斜率优化裸题。

有个很玄学的事情,就是我用\(f[i]=min\{f[j-1]+p[j].y*p[i].x\}\) 会很奇怪的Wa 。 明明和\(f[i]=min\{f[j]+p[j+1].y*p[i].x\}\)一模一样的呀!

如果有dalao愿意帮忙看一下就感激不尽了。

附上正确代码和错误代码

正确代码:

#include
typedef long long ll;using namespace std;const int maxn = 5e4+10;const ll inf = 10000000000000LL;struct qwq{ ll x,y; const bool operator < (const qwq rhs) const { if(this->x==rhs.x) return this->y
x
>n; for(int i = 1;i<=n;++i) cin>>tmp[i].x>>tmp[i].y; sort(tmp+1,tmp+1+n); ll mxy=0; for(int i = n;i;--i) { if(tmp[i].y>mxy) { mxy=tmp[i].y; p[++tot]=tmp[i]; } } reverse(p+1,p+1+tot);#ifdef force for(int i = 1;i<=tot;++i) { f[i]=inf; for(int j = 0;j
=slope(q[r],i)) --r; q[++r]=i; }#endif cout<
<

错误代码

#include
typedef long long ll;using namespace std;const int maxn = 5e4+10;const ll inf = 10000000000000LL;double esp = 1e-6;struct qwq{ ll x,y; const bool operator < (const qwq rhs) const { if(this->x==rhs.x) return this->y
x
>n; for(int i = 1;i<=n;++i) cin>>tmp[i].x>>tmp[i].y; sort(tmp+1,tmp+1+n); ll mxy=0; for(int i = n;i;--i) { if(tmp[i].y>mxy) { mxy=tmp[i].y; p[++tot]=tmp[i]; } } reverse(p+1,p+1+tot);#ifdef force for(int i = 1;i<=tot;++i) { f[i]=inf; for(int j = 1;j<=i;++j) { f[i]=min(f[i],f[j-1]+p[j].y*p[i].x); } }#endif#ifndef force l=r=1; q[1]=1; for(int i = 1;i<=tot;++i) { while(l
<=p[i].x) ++l; int j = q[l]; f[i]=f[j-1]+p[j].y*p[i].x; while(l
=slope(q[r],i)) --r; q[++r]=i+1; }#endif cout<
<

转载于:https://www.cnblogs.com/Syameimaru/p/10284869.html

你可能感兴趣的文章
POJ 3624 Charm Bracelet【01背包】
查看>>
Linux自动收集某个进程的脚本
查看>>
reverse() ; sort() ; sorted()
查看>>
Finalize/Dispose资源清理模式
查看>>
封装dialog弹窗
查看>>
使用synchronized(非this对象)同步代码块解决脏读问题
查看>>
Oracle中使用批处理文件批量建表
查看>>
Intel笔记本低压版CPU性能对比分析
查看>>
Gephi可视化(二)——Gephi Toolkit叫板Prefuse
查看>>
Fiddler环境配置教程
查看>>
第二阶段冲刺报告
查看>>
Vue.js 系列教程 5:动画
查看>>
WinForm 使用 HttpUtility
查看>>
Zabbix QQ报警配置
查看>>
2016.8.7 UnicodeEncodeError 同时遍历多个list
查看>>
基础 网络架构 网络硬件名词 网络通信协议
查看>>
sqlite
查看>>
关于Retinex图像增强算法的一些新学习。
查看>>
一道容易栽坑的有趣的面试题(关于js,定时器,闭包等)
查看>>
正则表达式,时间戳和日期互相转换
查看>>