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

    /****************************************************************************** * removeLineEndSpace ...

  2. .net core grpc 实现通信(一)

    现在系统都服务化,.net core 实现服务化的方式有很多,我们通过grpc实现客户端.服务端通信. grpc(https://grpc.io/)是google发布的一个开源.高性能.通用RPC(R ...

  3. dgraph cluster docker-compose 安装

    dgraph 是一款基于golang 的图数据库,使用了graphql+ 的查询方式 集群的安装官方也提供了对应的模版,比较简单 docker-compose 文件 我做了一些简单修改(数据存储的问题 ...

  4. vulcanjs 核心架构概念

    基于包的架构 为了保证系统的灵活以及可扩展,vulcanjs 使用基于包的架构设计,每一个功能都是一个包,可以方便的添加,移除 扩展.而不是修改 vulcan 的设计哲学是进行系统扩展,而不是编辑修改 ...

  5. 【MVC】Controller的使用

    1,控制器中所有的动作方法必须声明为public,如声明为private或protected,将不被视为动作方法. 如果将Action声明为private,或者是添加[NonAction]属性,则不对 ...

  6. go test 初始化--- TestMain的使用

    go test 功能,提高了开发和测试的效率. 有时会遇到这样的场景: 进行测试之前需要初始化操作(例如打开连接),测试结束后,需要做清理工作(例如关闭连接)等等.这个时候就可以使用TestMain( ...

  7. ubuntu 14.04 安装Eclipse与配置环境变量

    1. 安装JDK 1.1 源码包下载 首先到官网下载jdk,http://www.oracle.com/technetwork/java/javase/downloads/index.html,我下载 ...

  8. [ASP.NET MVC2 系列] ASP.Net MVC教程之《在15分钟内用ASP.Net MVC创建一个电影数据库应用程序》

    [ASP.NET MVC2 系列]      [ASP.NET MVC2 系列] ASP.Net MVC教程之<在15分钟内用ASP.Net MVC创建一个电影数据库应用程序>       ...

  9. ExtJS中,将Grid表头中的全选复选框取消复选

    今天发现公司产品用的EXTJS中使用Grid时,Grid表头中的全选复选框的选中状态不是很准确,就写了这个小扩展 在js中加入下面方法,在需要取消全选的地方调用即可,例:Ext.getCmp('gri ...

  10. 关于buffer,cache,wb,wt,clean,inv,flush,以及其他

    1. 有时候需要区分buffer和cache:buffer解决CPU写的问题,比如将多次写操作buffer起来一次性更新:cache解决CPU读的问题,将数据cache起来在下次读的时候快速取用. 2 ...