D. One-Dimensional Battle Ships
Time Limit: 2 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/567/problem/D

Description

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: nk 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 nk 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 from1 to m in the order the were made. If the sought move doesn't exist, then print "-1".

Sample Input

11 3 3
5
4 8 6 1 11

Sample Output

3

HINT

题意

在一维区间上,每次击打一个长度为1的区间,问在第几次(<=m)不能放这k*a的船,注意船与船不相互接触;

不存在输出-1;

题解

set寻找相邻x端点 维护值判断下就好了

代码

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef __int64 ll;
#define inf 1000000000000
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
} //************************************************************************************** set<int >s;
set<int >::iterator it,itt;
int n,k,a;
int sum;
bool test(int x)
{
it=s.lower_bound(x);
int r=*it;
int l=*(--it);
sum-=(r-l)/(a+);
sum+=((x-l)/(a+)+(r-x)/(a+));
if(sum<k)return true;
else return false;
}
int main()
{
scanf("%d%d%d",&n,&k,&a);
int m;
scanf("%d",&m);
s.insert();
s.insert(n+);
int x;
sum=(n+)/(a+);
if(sum<k)
{
printf("-1\n");
return ;
}
for(int i=; i<=m; i++)
{
scanf("%d",&x);
if(s.count(x))continue;
// for(it=s.begin();it!=s.end();it++)printf("%d\n",*it);
if(test(x))
{
printf("%d\n",i);
return ;
}//printf("%d\n",sum);
s.insert(x);
}
printf("-1\n"); return ;
}

Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set乱搞的更多相关文章

  1. map Codeforces Round #Pi (Div. 2) C. Geometric Progression

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

  2. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  3. Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set区间分解

    D. One-Dimensional Battle ShipsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  4. Codeforces Round #Pi (Div. 2)(A,B,C,D)

    A题: 题目地址:Lineland Mail #include <stdio.h> #include <math.h> #include <string.h> #i ...

  5. codeforces Round #Pi (div.2) 567ABCD

    567A Lineland Mail题意:一些城市在一个x轴上,他们之间非常喜欢写信交流.送信的费用就是两个城市之间的距离,问每个城市写一封信给其它城市所花费的最小费用和最大的费用. 没什么好说的.直 ...

  6. Codeforces Round #Pi (Div. 2) C. Geometric Progression map

    C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  7. Codeforces Round #Pi (Div. 2) B. Berland National Library set

    B. Berland National LibraryTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  8. Codeforces Round #Pi (Div. 2) A. Lineland Mail 水

    A. Lineland MailTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/proble ...

  9. Codeforces Round #Pi (Div. 2) E. President and Roads 最短路+桥

    题目链接: http://codeforces.com/contest/567/problem/E 题意: 给你一个带重边的图,求三类边: 在最短路构成的DAG图中,哪些边是必须经过的: 其他的(包括 ...

随机推荐

  1. 利用memcached构建高性能的Web应用程序(转载)

    面临的问题 对于高并发高访问的Web应用程序来说,数据库存取瓶颈一直是个令人头疼的问题.特别当你的程序架构还是建立在单数据库模式,而一个数据池连接数峰 值已经达到500的时候,那你的程序运行离崩溃的边 ...

  2. 关于windows系统下 webpack的使用

    最近包子在研究webpack打包,发现,真是个好东西,以前完全不懂,其实很简单,步骤如下: 1.安装webpack嘎嘎嘎嘎~~~ 2.初始化一下 3.这玩意是啥,我不知道,就依葫芦画瓢 4.这玩意是啥 ...

  3. [Effective JavaScript 笔记] 第8条:尽量少用全局对象

    初学者容易使用全局变量的原因 创建全局变量毫不费力,不需要任何形式的声明(只要在非函数里用var 你就可以得到一个全局变量) 写得代码简单,不涉及到大的项目或配合(写hello world是不会有什么 ...

  4. AspectJ报错:error at ::0 can't find referenced pointcut XXX

    今天在使用AspectJ进行注解切面时,遇到了一个错误. 切点表达式就是无法识别——详细报错信息如下: Exception in thread "main" org.springf ...

  5. ImageMagick资料

    ImageMagick资料 ---------------------------------------------------------------------------- ImageMagi ...

  6. Linux&shell之高级Shell脚本编程-创建函数

    写在前面:案例.常用.归类.解释说明.(By Jim) 使用函数 #!/bin/bash # testing the script function myfun { echo "This i ...

  7. Django 的css和js压缩插件:django_compressor

    今天尝试了django_conpressor,一个在django框架中压缩css和js的插件,灰常有用 我把它加载在我的base的HTML template中,原来未经压缩的css和js是: < ...

  8. SharePoint Word 转换PDF服务介绍及示例

    前言:在SharePoint使用过程中,经常会发现将文档进行格式转换的需求,之前,看到SharePoint 2013有将PPT转换PDF文档的服务,后来,才发现SharePoint 2010开始,就有 ...

  9. eclipse 启动后,啥也不干,就一直在loading descriptor for XXX (XXX为工程名),,其他什么操作都不能操作。 如下图所示,保存文件也无法保存。 这个怎么办?一年好几天,什么都干不了!!!!!

    解决办法: 解决办法是 断一下网就好了

  10. 38.输出1到最大的N位数[Print 1 to max number of N bits]

    [题目] 输入数字n,按顺序输出从1最大的n位10进制数.比如输入3,则输出1.2.3一直到最大的3位数即999. [分析] 这是一道很有意思的题目.看起来很简单,其实里面却有不少的玄机. [常规思路 ...