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 ...
随机推荐
- [转载]Oracle PL/SQL之LOOP循环控制语句
在PL/SQL中可以使用LOOP语句对数据进行循环处理,利用该语句可以循环执行指定的语句序列.常用的LOOP循环语句包含3种形式:基本的LOOP.WHILE...LOOP和FOR...LOOP. LO ...
- 关于字符串split一些用法
split方法在大数据开发中的多用于日志解析及字段key值分割,最近需求中碰到一个问题在 无论怎么分割都会出现数组下标越界问题, 由于前台在sdk中多加了几个字段(测试数据很少,大多为空) ,需要我们 ...
- jquery easyui datagrid 空白条处理 自适应宽高 格式化函数formmater 初始化时会报错 cannot read property 'width'||'length' of null|undefined
1---表格定义好之后右侧可能会有一个空白条 这个空白条是留给滚动条的,当表格中的一页的数据在页面中不能全显示时会自动出现滚动条,网上有很多事要改源码才可以修改这个,但是当项目中多处用到时,有的需要滚 ...
- Java中高级面试必问之多线程TOP50(含答案)
以下为大家整理了今年一线大厂面试被问频率较高的多线程面试题,由于本人的见识局限性,所以可能不是很全面,也欢迎大家在后面留言补充,谢谢. 1.什么是线程? 2.什么是线程安全和线程不安全? 3.什么是自 ...
- python-selenium,关于页面滑动的操作
//移动到元素element对象的“顶端”与当前窗口的“顶部”对齐 ((JavascriptExecutor) driver).executeScript("arguments[0].scr ...
- Spring Maven 包的依赖
<properties> <spring.version>4.3.11.RELEASE</spring.version> </properties> & ...
- 3 字节的 UTF-8 序列的字节 3 无效 解决
参考下列应该可以解决,笔者为3. 1.https://blog.csdn.net/hostel_2/article/details/51517361 2.https://blog.csdn.net/u ...
- Nginx 容器教程
春节前,我看到 Nginx 加入了 HTTP/2 的 server push 功能,就很想试一下. 正好这些天,我在学习 Docker,就想到可以用 Nginx 容器.万一哪里改乱了,直接删掉,再重启 ...
- indexOf()/equals/contains
indexOf():对大小写敏感定义:返回某个指定字符串值在字符串中首次出现位置用法:返回字符中indexof(string)中字串string在父串中首次出现的位置,从0开始!没有返回-1:方便判断 ...
- libvirt的security
1. libvirt支持SASL authentication and encryption MD5 hashes are considered unsafe and should not be us ...