ioi2016aliens
/*
首先考虑点在直线的两边效果一样 于是转移到一边
之后发现当我们覆盖某些点时,有其他的一些点一定会被覆盖 我们找出所有必须覆盖的点
之后我们发现我们找到的这些点 将其按照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 + ].y;}
double Y(int x) {return dp[x] - * p[x + ].y + p[x + ].y * p[x + ].y;}
double slope(int x, int y) {return (Y(x) - Y(y)) / (X(x) - X(y));} int solve(ll x)
{
h = , t = , q[] = ;
for(int i = ; i <= tot; i++)
{
while(h < t && 2.0 * p[i].x > slope(q[h], q[h + ])) h++;
dp[i] = dp[q[h]] + (p[i].x - p[q[h] + ].y + ) * (p[i].x - p[q[h] + ].y + ) + x;
sm[i] = sm[q[h]] + ;
if(i == tot) break;
if(p[i + ].y <= p[i].x) dp[i] -= (p[i].x - p[i + ].y + ) * (p[i].x - p[i + ].y + );
while(h < t && slope(q[t], q[t - ]) > 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 = ; 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 = ; 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()) <= k) {
return dp[tot];
}
ll L = , R = 1ll * m * m + ;
while(L <= R)
{
ll mid = (L + R) >> ;
if(solve(mid) <= k) R = mid - , ans = dp[tot];
else L = mid + ;
}
// 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 6 2 6 2
1 4
4 1 4 4 4
1 0 2 2
3 1 1 2 1 3
0 1
2 1
2 2
*/
ioi2016aliens的更多相关文章
随机推荐
- Listbox Binding ItemsSource
把List<CourseItem>绑定到ListBox. 前台绑定: <ListBox x:Name="ItemBox" Grid.Row="1&quo ...
- kafka集群安装,配置
1.安装+配置(集群) 192.168.0.10.192.168.0.11.192.168.0.12(每台服务器kafka+zookeeper) # kafka依赖java环境,需要提前安装好jdk. ...
- HDU 1234:开门人和关门人
开门人和关门人 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- java面试题12
1. jsp与servlet的区分? 答:Servlet和JSP都是基于java语言上的动态网页技术,Servlet程序其实就是java程序,只不过它所使用的类库为JAVA Servlet API, ...
- 配置搭建与使用redis
redis单点.redis主从.redis哨兵 sentinel,redis集群cluster配置搭建与使用 redis是如今被互联网公司使用最广泛的一个中间件,我们打开GitHub搜索redis,边 ...
- The Suspects 并查集
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...
- Fire! 又是图 bfs
Joe works in a maze. Unfortunately, portions of the maze havecaught on re, and the owner of the ma ...
- chrom 自带截屏用法
1 . F12调出控制台 2 . Ctrl+Shift+p 3 . 输入capture
- JAVA中神奇的双刃剑--Unsafe
前提 参考资料: Java魔法类:sun.misc.Unsafe 在openjdk8下看Unsafe源码 Unsafe介绍 在Oracle的Jdk8无法获取到sun.misc包的源码,想看此包的源码可 ...
- 解决:VS2010 调试器无法继续继续运行该进程,无法启动调试
工具栏上突然出现 Model Project选项插件,在调试项目的时候突然出现错误: 按照网上的一些方法弄了后还是同样报错,把本地代码删除后从库上重现拉下来的项目依然报错,到这里就明白不是项目本身问题 ...