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的更多相关文章
随机推荐
- VS2015 Release 生成调试信息
- C/C++ > 常规 > 调试信息格式 - C/C++ > 优化 > 优化 > 禁止(/Od) - 链接器 > 调试 > 生成调试信息 > 是 (/ ...
- CodeForces - 645F:Cowslip Collections (组合数&&欧拉函数)
In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning t ...
- HDU1081 最大字段和 压缩数组(单调队列优化)
最大字段和题型,推荐做题顺序: HDU1003 HDU1024 HDU1081 ZOJ2975 ZOJ2067 #include<cstdio> #include<cstdlib& ...
- ubuntu mongodb backup/restore (备份和恢复)
备份(导出) 1.导出单个collection-.json格式 mongoexport --host:127.0.0.1 --port:27017 --db test --collection tes ...
- The Alphabet Sticker
题目大意:给你一串字符串,其中有一部分未知,用'?'表示. 现在定义一种合法的Sticker,比如"aabcc","ccccab".即所有相同的字母要在一起才是 ...
- 大家一起做训练 第一场 A Next Test
题目来源:CodeForce #27 A 题目的意思简而言之就是要你输出一个没有出现过的最小的正整数. 题意如此简单明了,做法也很明了. 直接读入所有的数,然后排个序,设置个变量从1开始,出现过+1, ...
- ACM中的取模
取模本身的性质:(之前有一篇博客写过)三则运算(+,-,*)过程中的取模与最后的取模一样(前提是最后不超long long(或int) 范围,所以为防止超范围,直接对三则运算中的过程取模) 然后就是A ...
- BZOJ1835,LG2605 [ZJOI2010]基站选址
题意 有N个村庄坐落在一条直线上,第i(i>1)个村庄距离第1个村庄的距离为\(D_i\) 需要在这些村庄中建立不超过K个通讯基站,在第i个村庄建立基站的费用为\(C_i\) 如果在距离第i个村 ...
- ZH奶酪:Python使用ElementTree解析XML【译】
19.7. xml.etree.ElementTree — The ElementTree XML API 源代码: Lib/xml/etree/ElementTree.py Element类型是一种 ...
- 用newLISP通过SMTPserver发送邮件
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/sheismylife/article/details/26633073 直接使用标准模块smtpx. ...