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的更多相关文章

  1. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  2. Codeforce Round #216 Div2

    e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...

  3. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

  4. codeforce 375_2_b_c

    codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...

  5. codeforce 367dev2_c dp

    codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...

  6. 三维dp&codeforce 369_2_C

    三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...

  7. 强连通分量&hdu_1269&Codeforce 369D

    强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...

  8. 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D

    [树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...

  9. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

随机推荐

  1. CI框架不能有Index控制器

    今天部署了ci框架,想用用它.创建别的控制器没什么错误.但是我创建了一个Index控制器,并访问了index方法,报错了.但是直接在方法中写输出就没事.而且方法名称改为其他部位index的也能访问. ...

  2. 微信公众号内H5调用微信支付国内服务商模式

    最近在折微信公众号内H5用JSAPI调用微信支付,境内服务商版支付,微信支付给出的官方文档以及SDK不够详细,导至我们走了一些弯路,把他分享出来,我这边主要是用PHP开发,所以未加说的话示例都是PHP ...

  3. BizTalk开发系列(二十) 类型作用域

    Orchestration中的Type概念跟.NET 里的Class一样,可以在Orchestration开过过程中将多个实例绑定到一种类型.Orchestration 视图里包括的类型有Port T ...

  4. IOS第15天(2,事件处理hitTest练习)

    ***hitTest 获取最合适的点 @implementation HMGreenView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEv ...

  5. Yii源码阅读笔记(二十七)

    Theme 类,即一个应用的主题,主要通过替换路径实现主题的应用,里边的方法为获取根路径和根链接,以及应用主题的方法: namespace yii\base; use Yii; use yii\hel ...

  6. JNDI数据源局部配置(解决Cannot create JDBC driver of class '' for connect URL 'null')

    最开始,我是借鉴 孤傲苍狼的JNDI教程去做的,他讲得很详细,但是坏处也就是因为他讲的太详细.查了很多书,都是建议说不要用全局去配置JNDI,一是要修改tomcat的server.xml,容易破坏to ...

  7. J2EE用户CPU占用过大后的分析过程

        1.找到最耗CPU的java线程ps命令 命令:ps -mp pid -o THREAD,tid,time   或者  ps -Lfp pid 结果展示:            2.可以获取到 ...

  8. fight

    为啥用block  copy. 从栈到拷贝到堆 循环引用,控制器引用block. block里面调用 self self引用控件,控件引用block,block里面引用self http://www. ...

  9. [daily][archlinux][fonts] 在linux下管理字体

    序: linux是社区搞出来, 商业应用也都是服务器场景.社区里又都是技术人员.字体又是细节.而且会英文早成了标配.所以没有很多社区以外的人力来搞字体这个毫无回报的东西. 结果很自然的,装linux桌 ...

  10. LightOj 1213 - Fantasy of a Summation(推公式 快速幂)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1213 #include <stdio.h> int cases, case ...