/*
首先考虑点在直线的两边效果一样 于是转移到一边
之后发现当我们覆盖某些点时,有其他的一些点一定会被覆盖 我们找出所有必须覆盖的点
之后我们发现我们找到的这些点 将其按照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的更多相关文章

随机推荐

  1. Hign-Speed Tracking with Kernelzied Correlation Filters

    reference:Hign-Speed Tracking with Kernelzied Correlation Filters questions: The core componet of mo ...

  2. Mac锁屏快捷键

    Mac 锁屏快捷键 直接盖 -- 推荐,因为帅 control + command + Q -- 真正意义上的锁屏.可行 control + shift + Power -- 只是黑屏,再次打开不需要 ...

  3. chapter02 回归模型在''美国波士顿房价预测''问题中实践

    #coding=utf8 # 从sklearn.datasets导入波士顿房价数据读取器. from sklearn.datasets import load_boston # 从sklearn.mo ...

  4. 抓老鼠 codeForce 148D - Bag of mice 概率DP

    设dp[i][j]为有白老鼠i只,黑老鼠j只时轮到公主取时,公主赢的概率. 那么当i = 0 时,为0 当j = 0时,为1 公主可直接取出白老鼠一只赢的概率为i/(i+j) 公主取出了黑老鼠,龙必然 ...

  5. (3)re模块(正则表达式模块)

    什么是正则表达式 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则.(在Python中)它内嵌在Python中,并通过 r ...

  6. Microsoft-Excel Sheet Column Number

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

  7. gtx860M,cuda9路1080p多高斯运动检测测试

    多高斯背景差分,非常吃cpu,特别是多路视屏,所以想用gpu做检测 后面的跟踪一系列的规则判断用cpu opencv+cuda+stl做了个测试 代码: // MTTestCudaMog.cpp : ...

  8. index.do

  9. grandstack graphql 开发模型

    当前grandstack 支持两类开发方式 js (使用Neo4j-graphql-js) 插件模型 js 模型 参考https://github.com/rongfengliang/grand-st ...

  10. 和为 s 的两个数字(和为 s 的连续正数序列)

    题目 输入一个递增排序的数组和一个数字 s,在数组中查找两个数,得它们的和正好是 s.如果有多对数字的和等于 s,输出任意一对即可 思路 我们先在数组中选择两个数字,如果它们的和等于输入的 s,我们就 ...