codeforces gym 100947 J. Killing everything dp+二分
4 seconds
64 megabytes
standard input
standard output
There are many enemies in the world such as red coders and hackers. You are trying eliminate everybody. Everybody is standing on a road, which is separated into 109 sections. The sections are numbered 1, 2, 3, 4, …109 from west to east. You want to kill N enemies. The ith enemy will be standing on the section Ai. In order to kill the enemies, you prepared P small bombs and Q large bombs. You can choose a positive integer w as a parameter for energy consumption. Then, a small bomb can kill all enemies in at most w consecutive sections, and a large bomb can kill all enemies of at most 2w consecutive sections.
Enemies can be killed by more than one bomb. You want to kill all enemies. Since it is expected that many civilians will walk down that road, for the sake of safety, you have to fix the positions of the bombs and minimize the value of w.
So you decided to Write a program that, given information of the enemies and the number of bombs, determine the minimum value of w so all enemies can be killed.
The input consists of several test cases, the first line contains the number of test cases T. For each test case: The first line of input contains three space separated integers N, P, Q (1 ≤ N ≤ 2000, 0 ≤ P ≤ 105, 0 ≤ Q ≤ 105), where N is the number of the enemies, P is the number of small bombs, and Q is the number of large bombs.
The ith line (1 ≤ i ≤ N) of the following N lines contains an integer Ai, the section where the ith enemy will be standing.
Output: For each test cases print the solution of the problem on a new line.
1
3 1 1
2
11
17
4
In the sample test case you have 3 enemies at positions: 2, 11, 17.
For w = 4, one possible solution is to throw one small bomb on segment 1 - 4, and one large bomb on segment 11 - 18. This configuration will kill all three enemies.
There is no configuration with w < 4 that can kill them all.
题意:给你n个位置,p个小炸弹,q个大炸弹;小炸弹可以连续炸w长度,大炸弹可以连续炸2*w长度
思路:显然二分答案求最小的w,问题在于如何check;
dp[i][j]表示炸完i之前所有点,使用j个小炸弹,最少需要多少个大炸弹;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-4
#define bug(x) cout<<"bug"<<x<<endl;
const int N=2e3+,M=5e5+,inf=1e9+,mod=1e9+;
const LL INF=1e18+,MOD=1e9+; int n,p,q;
int nex[N][];
int dp[N][N],a[N];
int check(int x)
{
for(int i=;i<=n;i++)
{
nex[i][]=lower_bound(a+,a+n+,a[i]+x)-a;
if(*x-inf+a[i]>)nex[i][]=n+;
else nex[i][]=lower_bound(a+,a+n+,a[i]+x+x)-a;
}
for(int i=;i<=n+;i++)
{
for(int j=;j<=p;j++)
dp[i][j]=inf;
}
dp[][]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=p;j++)
{
int v=nex[i][];
dp[v][j+]=min(dp[v][j+],dp[i][j]);
v=nex[i][];
dp[v][j]=min(dp[v][j],dp[i][j]+);
}
}
for(int i=;i<=p;i++)
if(dp[n+][i]<=q)return ;
return ;
}
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&p,&q);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
if(p+q>=n)
{
printf("1\n");
continue;
}
sort(a+,a++n);
a[n+]=inf*;
int s=;
int e=inf,ans=-;
while(s<=e)
{
int mid=(s+e)>>;
//cout<<mid<<endl;
if(check(mid))
e=mid-,ans=mid;
else s=mid+;
}
printf("%d\n",ans);
}
return ;
}
codeforces gym 100947 J. Killing everything dp+二分的更多相关文章
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
		2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ... 
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
		[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ... 
- Codeforces GYM 100876 J - Buying roads 题解
		Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ... 
- Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希
		https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ... 
- codeforces Gym 100187J J. Deck Shuffling dfs
		J. Deck Shuffling Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ... 
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
		Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ... 
- codeforces GYM 100114 J. Computer Network 无相图缩点+树的直径
		题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” ... 
- codeforces Gym 100500  J. Bye Bye Russia
		Problem J. Bye Bye RussiaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1005 ... 
- Codeforces Gym 100500F Problem F. Door Lock 二分
		Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ... 
随机推荐
- UVALive 3295  Counting Triangles
			题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ... 
- POJ 3662	Telephone Lines (二分 + 最短路)
			Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncoop ... 
- zabbix 服务端安装(server)
			zabbix版本:Zabbix 2.2 LTS 备注:Linux下安装zabbix需要有LAMP或者LNMP运行环境 准备篇: 一.Web环境:Nginx+MySQL+PHP CentOS 7.0编译 ... 
- 怎样从外网访问内网Lighttpd?
			本地安装了一个Lighttpd,只能在局域网内访问,怎样从外网也能访问到本地的Lighttpd呢?本文将介绍具体的实现步骤. 准备工作 安装并启动Lighttpd 默认安装的Lighttpd端口是80 ... 
- Oracle之用户和表空间
			用户和表空间 看具体下载什么来操作?(oracle 11g,终端) 如果不在虚拟桌面, 它在整个总账项目里占什么位置? 如何使用? 不管学什么都要及时复习和总结,很重要. 增删改查 decode ... 
- JDK源码之ReentrantLock
			1.定义 ReentrantLock是一种可重入锁,允许一个线程对同一个资源重复加锁,如果说是当一个线程调用一个锁的lock()方法,然后再次调用锁的lock()方法,当锁不支持可重入时,该线程会被自 ... 
- php定界符<<<EOF讲解
			Heredoc技术.可用来输出大段的html和javascript脚本 1.PHP定界符的作用就是按照原样,包括换行格式什么的,输出在其内部的东西: 2.在PHP定界符中的任何特殊字符都不需要转义: ... 
- GitHub使用笔记2:github常用操作
			1: 绑定ssh keys 2:github新建仓库 echo "# SpringStack" >> README.md git init git add README ... 
- sql xml 入门 (二)
			DECLARE @myDoc xml --http://www.paymob.cn --话费充值api,充值api,话费充值接口,手机话费充值,车贝手机,贝萌手机,移动话费充值,联通话费充值,电信话费 ... 
- 本地win7ping VM linux ipv6地址问题
			前述 在windows和linux同时安装ipv6之后,系统将会自动分配一个link-local(链接本地)地址也就是ifconfig -a看到的一行[inet6 addr: fe80::20c:29 ... 
