/*
首先考虑点在直线的两边效果一样 于是转移到一边
之后发现当我们覆盖某些点时,有其他的一些点一定会被覆盖  我们找出所有必须覆盖的点
之后我们发现我们找到的这些点 将其按照x递增排序 那么y也是递增的
然后我们 可以得到转移方程了 令dp[i][j]表示前i个都覆盖到了,用了j个正方形的最小花费然后我们考虑转移时的枚举dp[i][j] = min(dp[i][k] + (x[i] - y[k + 1] + 1) ^ 2;这个是显然NKN的, 斜率优化后NK, wqs二分后Nlogm *///#include "aliens.h"
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
#define M 100010
#define ll long long
#define inf 0x3f3f3f3f
struct Note{ll x, y;bool operator < (const Note &b) const{return this->x == b.x ? this->y > b.y : this->x < b.x;}
}note[M], p[M];
int tot,q[M],h,t, sm[M];
ll dp[M], ans;double X(int x) {return p[x + 1].y;}
double Y(int x) {return dp[x] - 2 * p[x + 1].y + p[x + 1].y * p[x + 1].y;}
double slope(int x, int y) {return (Y(x) - Y(y)) / (X(x) - X(y));} int solve(ll x)
{h = 1, t = 1, q[1] = 0;for(int i = 1; i <= tot; i++){while(h < t && 2.0 * p[i].x > slope(q[h], q[h + 1])) h++;dp[i] = dp[q[h]] + (p[i].x - p[q[h] + 1].y + 1) * (p[i].x - p[q[h] + 1].y + 1) + x;sm[i] = sm[q[h]] + 1;if(i == tot) break;if(p[i + 1].y <= p[i].x) dp[i] -= (p[i].x - p[i + 1].y + 1) * (p[i].x - p[i + 1].y + 1);while(h < t && slope(q[t], q[t - 1]) > slope(q[t], i)) t--;q[++t] = i; }return sm[tot];
}long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {for(int i = 0; i < n; i++) {note[i].y = r[i], note[i].x = c[i];if(note[i].x < note[i].y) swap(note[i].x, note[i].y);}sort(note, note + n);for(int i = 1; i < n; i++)    {while(h <= t && note[i].y <= note[q[t]].y ) t--;q[++t] = i;}for(int i = h; i <= t; i++){tot++;p[tot].x = note[q[i]].x, p[tot].y = note[q[i]].y;}if((ans = solve(0)) <= k) {return dp[tot];}ll L = 0, R = 1ll * m * m + 10;while(L <= R){ll mid = (L + R) >> 1;if(solve(mid) <= k) R = mid - 1, ans = dp[tot];else L = mid + 1;}
//    if(ans - 1ll * R * k - k == 568367396612){solve(107455936237); return sm[tot];}return ans - 1ll * R * k - k;
}
/*
5 7 2
0 4 4 4 4
3 4 6 5 62 6 2
1 4
4 14 4 4
1 0 2 2
3 1 1 21 3
0 1
2 1
2 2
*/

转载于:https://www.cnblogs.com/luoyibujue/p/9147206.html

ioi2016aliens相关推荐

最新文章

  1. 卡片右上角三角形效果,按钮点击变色
  2. 深度学习如何又好又快? Google发布最新《高效深度学习: 更小、更快、更好》综述...
  3. BSD和云 – 不可错过的BSD聚会
  4. hibernate教程--持久化类状态详解
  5. Linux环境下搭建FTP服务器
  6. Nginx的Gzip模块配置指令(一)
  7. python flask项目过程_Python 开发过程遇到的问题
  8. No module named 'Tkinter'
  9. Python 多版本共存问题
  10. SpringBoot 的属性配置文件
  11. AD20元件重叠绿色报错的解决方法,距离太近绿色报错
  12. Uiautomator 2.0之UiObject2类学习小记
  13. 智慧物流园区供应链管理系统解决方案:数智化供应链赋能物流运输行业供应链新模式
  14. PHP集成环境MxSrvs如何安装pcntl扩展
  15. AT89S52单片机思维导图
  16. 解决:error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“
  17. python爬虫re+requests+bs4爬取汽车之家全部过程,附代码。支持互联网免费至上,看了全部关于汽车之家的文章都是收费的,我很看不过去
  18. 微信小程序-中英文文本换行的小问题
  19. dtm文件生成等高线 lisp_CAD2000下DTM的建立
  20. Tensorflow学习-自定义模型

热门文章

  1. 制作查询数据窗口php,pb 检索数据窗口做条件查询 | 学步园
  2. Failed to shutdown DBConsole Gracefully
  3. JTAG、SWD、JLINK、ST-LINK、ULINK的区别
  4. Linux基础命令学习——实战篇(给swap分区增加500M)
  5. 记一次微信公众号的开发与后台搭建
  6. 交换机的116个知识点 (1)
  7. Ubuntu 18.04 安装ns-3.30
  8. Dew Lab Studio 2020 VCL软件包,很好的RAD(快速软件开发)工具
  9. word页码自增、页眉页脚的增长
  10. mysql怎么删除表中字段的数据库表_Mysql 数据库 表 字段的创建 修改 删除