Codeforce 567D
One-Dimensional Battle Ships
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).
At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies a sequence of a consecutive squares of the field). The ships cannot intersect and even touch each other.
After that Bob makes a sequence of “shots”. He names cells of the field and Alice either says that the cell is empty (“miss”), or that the cell belongs to some ship (“hit”).
But here’s the problem! Alice like to cheat. May be that is why she responds to each Bob’s move with a “miss”.
Help Bob catch Alice cheating — find Bob’s first move, such that after it you can be sure that Alice cheated.
Input
The first line of the input contains three integers: n, k and a (1 ≤ n, k, a ≤ 2·105) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the n, k and a are such that you can put k ships of size a on the field, so that no two ships intersect or touch each other.
The second line contains integer m (1 ≤ m ≤ n) — the number of Bob’s moves.
The third line contains m distinct integers x1, x2, …, xm, where xi is the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n.
Output
Print a single integer — the number of such Bob’s first move, after which you can be sure that Alice lied. Bob’s moves are numbered from 1 to m in the order the were made. If the sought move doesn’t exist, then print “-1”.
Sample test(s)
Input
11 3 3
5
4 8 6 1 11
Output
3
Input
5 1 3
2
1 5
Output
-1
Input
5 1 3
1
3
Output
1
题意:大意是给你k个长度为a的船,以及一个长度为n的地方,船不能相邻或相交,再给你m个箭,,这个箭射的位置不能有船,输出到哪个位置一定会有船,否则输出-1.
二分答案,每次2分箭射的地方,找到上界和下界
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
typedef long long LL;
const int Max = 1e5+100;
int n,k,a,m;
int boat[2*Max];
bool Judge(int x)
{
int len=0;
int ans=0;
for(int i=1;i<=n;i++)
{
len++;
if(boat[i]&&boat[i]<=x)
{
len=0;
}
if(len>=a)
{
len=-1;
ans++;
}
if(ans>=k)
{
return false;
}
}
return true;
}
int main()
{
scanf("%d %d %d %d",&n,&k,&a,&m);
int data;
for(int i=1;i<=m;i++)
{
scanf("%d",&data);
boat[data]=i;
}
int L=1,R=m;
int ans=-1;
while(L<=R)
{
int mid=(L+R)>>1;
if(Judge(mid))
{
ans=mid;
R=mid-1;
}
else
{
L=mid+1;
}
}
printf("%d\n",ans);
return 0;
}
Codeforce 567D的更多相关文章
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 375_2_b_c
codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...
- codeforce 367dev2_c dp
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- 强连通分量&hdu_1269&Codeforce 369D
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...
- 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D
[树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
随机推荐
- PowerDesigner V16.5 安装文件 及 破解文件
之前在网上找个假的,只能看,不能创建自己的DB; 或者 不能破解的,比较伤脑筋. 偶在这里提供一个 可长期使用的版本. PowerDesigner165_破解文件.rar 链接:http://p ...
- LFS初次成功+如何粘贴复制LFS命令
搞了几次LFS,终于成功了,总算舒了一口气. 这次搞LFS用到的资料:LFS文档:http://www.ha97.com/book/lfs-book-6.6/index.html 一份简单的指导文章 ...
- vi/vim初步接触
vi和vim一直被人津津乐道,到底是什么使得它们如此受欢迎? vi分为3种模式:一般模式,编辑模式,命令行模式. (1)一般模式: 进入vi后,默认就是一般模式. 用处:方便地移动光标,删除字符/整行 ...
- 未找到arm-linux-gcc解决办法
sudo tar jxvf arm-linux-gcc.4.3.3.tar.bz2 export PATH=$PATH:/usr/local/arm/2.95.3/bin #/usr/local/ar ...
- Unity学习疑问记录之隐藏与显示物体
Unity3D中隐藏与显示物体的一些操作 http://unity3d.9tech.cn/news/2013/0930/33019.html
- RadioButton Control
Horizontal Radiobuttons Column2 is DataGridViewTextBoxCell Horizontal Custom Radiobuttons => usin ...
- 小吐槽Toolbar
最近弄界面 要吧全部图标改成PNG格式 虽说从2010以后Delphi默认支持PNG格式图片, 但是想应用到按钮上, 似乎除了TButton意外, 也只能ToolBar可以正常显示了, 其他的, 比如 ...
- C输入输出函数与缓冲区
#转 对C语言输入输出流和缓冲区的深入理解C语言缓冲区(缓存)详解缓冲区又称为缓存,它是内存空间的一部分.也就是说,在内存空间中预留了一定的存储空间,这些存储空间用来缓冲输入或输出的数据,这部分预留的 ...
- ios开发xcode中设置代码块
在开发中有很多重复的代码,很多开发者把常用的代码做成代码块提高开发效率. 在xcode里选中代码块的时候总是很不容易,点击选中的代码(文字),不要移动和松开鼠标左键,当竖线变成像拉长了的x(我也不知道 ...
- 根据value选择select
<script> var tem="{$Zgoods.type_2}"; $("#type_2 option[value='"+tem+" ...