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. JS 循环遍历JSON数据

    JSON数据如:{"options":"[{/"text/":/"王家湾/",/"value/":/" ...

  2. CentOS6.5安装iftop

    iftop这个小工具是Linux和unix下的top命令升级版,功能相对较强,界面易懂.今天安装了CentOS6.5的最新版,装个小工具检查下系统运行性能. 官网:http://www.ex-parr ...

  3. 设置dom元素可拖动,支持ie5+

    摘要: 最近在项目中要做一个图片预览的功能,这时候会遇到用户上传很大的图片,已经超出视图界面.最终决定做一个在固定宽和高的位置,用户可以拖动图片查看.所以自己就写了一个支持ie5+,chrome,Fi ...

  4. POJ 1836 Alignment

    Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...

  5. PHP常量PHP_SAPI与函数php_sapi_name()简介,PHP运行环境检测

    php_sapi_name() 是用来检测PHP运行环境的函数. 该函数返回一个描述PHP与WEB服务器接口的小写字符串. 例如:aolserver, apache,apache2filter, ap ...

  6. Linux 日志文件utmp、wtmp、lastlog、messages

            1.有关当前登录用户的信息记录在文件utmp中:==who命令 2.登录进入和退出纪录在文件wtmp中:==w命令 3.最后一次登录文件可以用lastlog命令察看: 4.messag ...

  7. zb的生日

    http://acm.nyist.net/JudgeOnline/problem.php?pid=325 zb的生日 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 ...

  8. python 最佳入门实践

    勿在浮沙筑高台,无论什么技术,掌握核心精神和api,是很重要的. 但是入门过程也可能不是一帆风顺的,这里有八个入门任务,看看你完成了没有: http://code.tutsplus.com/artic ...

  9. BZOJ 1455

    STL的基本用法 (居然能空间卡过去= =!!!) #include <cstdio> #include <ext/pb_ds/priority_queue.hpp> #inc ...

  10. java中queue的使用

    Queue接口与List.Set同一级别,都是继承了Collection接口.LinkedList实现了Queue接 口.Queue接口窄化了对LinkedList的方法的访问权限(即在方法中的参数类 ...