题目链接

双倍经验

设\(H\)表示长,\(W\)表示宽。

若\(H_i<H_j\)且\(W_i<W_j\),显然\(i\)对答案没有贡献。

于是把所有点按\(H\)排序,然后依次加入一个按\(W\)降序排序的单调栈。

这个单调栈里就是一定对答案有贡献的点,现在的问题就是把这些点分段,使总费用最小。

设\(f[i]\)表示前\(i\)块土地的最小费用。

然后枚举断点\(0<=j<i\),则\(f[i]=\min(f[j]+W_{j+1}*H_i)\)

斜率优化搞一搞就行了。

// f[i] = f[j] + x[i] * y[j + 1]
// f[j] = -x[i] * y[j + 1] - f[i]
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 50010;
#define ll long long
inline ll min(const ll a, const ll b){
return a < b ? a : b;
}
int n, top;
struct point{
int x, y;
int operator < (const point A) const{
return x != A.x ? x < A.x : y < A.y;
}
}a[MAXN], st[MAXN];
int q[MAXN], head, tail;
ll f[MAXN];
inline double k(int i, int j){
return (f[i] - f[j]) / (st[i + 1].y - st[j + 1].y);
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d%d", &a[i].x, &a[i].y);
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; ++i){
while(top && st[top].y <= a[i].y) --top;
st[++top] = a[i];
}
for(int i = 1; i <= top; ++i){
while(head < tail && k(q[head], q[head + 1]) > -st[i].x) ++head;
int j = q[head];
f[i] = f[j] + (ll)st[i].x * st[j + 1].y;
while(head < tail && k(q[tail - 1], q[tail]) <= k(q[tail], i)) --tail;
q[++tail] = i;
}
printf("%lld\n", f[top]);
return 0;
}

最新文章

  1. PHP的输出缓冲区(转)
  2. 大数据系列(3)——Hadoop集群完全分布式坏境搭建
  3. [ZigBee] 14、Zigbee无线通信前奏——BasicRF 简单无线点对点传输协议
  4. linux_shell_4_shell特性
  5. 云服务器 ECS Linux 系统盘数据转移方法
  6. while DEMO
  7. Object-C中需要注意的小细节
  8. Zookeeper 脑裂
  9. 04.Hibernate一对一关联
  10. POJ 3243 Clever Y (求解高次同余方程A^x=B(mod C) Baby Step Giant Step算法)
  11. 统计nginx日志里流量
  12. 配置Ubuntu开发环境
  13. 浙大PTA - - File Transfer
  14. 详细比较三个 CSS 预处理器(框架):Sass、LESS 和 Stylus
  15. javascript学习(9)——[设计模式]单例
  16. MVC EF 修改 封装类 通用泛型方法(一)
  17. Ant自动构建
  18. 32位机器的LowMemory
  19. Android 的自动化测试资源
  20. Linux mount BSD disk partition

热门文章

  1. ZOJ 2060 A-Fibonacci Again
  2. 小程序解密 encryptedData 获取 unionID 等信息
  3. java和mysql的length()区别及char_length()
  4. Java中TimeZone类的常用方法
  5. Javascript中判断变量是数组还是对象(array还是object)
  6. Appium与Robotium区别
  7. DP——P2300 合并神犇
  8. [HNOI2014]江南乐 博弈论
  9. 【JavaScript】BOM
  10. tomcat7.x远程命令执行(CVE-2017-12615)漏洞漏洞复现