博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF 567D(One-Dimensional Battle Ships-二分)
阅读量:4638 次
发布时间:2019-06-09

本文共 3217 字,大约阅读时间需要 10 分钟。

D. 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: 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 test(s)
input
11 3 354 8 6 1 11
output
3
input
5 1 321 5
output
-1
input
5 1 313
output
1

裸二分

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i
=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (200000+10)typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int n,k,a,m;int x[MAXN],x2[MAXN];bool check(int m){ For(i,m) x2[i]=x[i]; sort(x2+1,x2+1+m); int l=1,tot=0; For(i,m) { int len=x2[i]-l+1; tot+=len/(a+1); l=x2[i]+1; } tot+=(n+1-l+1)/(a+1); if (tot>=k) return 1; return 0;}int main(){// freopen("D.in","r",stdin);// freopen(".out","w",stdout); cin>>n>>k>>a>>m; For(i,m) scanf("%d",&x[i]); int l=1,r=m,ans=INF; while(l<=r) { int m=(r+l)/2; if (check(m)) l=m+1; else r=m-1,ans=min(ans,m); } if (ans==INF) ans=-1; cout<
<

转载于:https://www.cnblogs.com/brucemengbm/p/6906778.html

你可能感兴趣的文章
hdu 4289 网络流拆点,类似最小割(可做模板)邻接矩阵实现
查看>>
58前端内推笔试2017(含答案)
查看>>
写给自己的web开发资源
查看>>
Java学习笔记
查看>>
sprintf 和strcpy 的差别
查看>>
打表打表何谓打表?
查看>>
MPEG4与.mp4
查看>>
实验5
查看>>
git 下载 安装
查看>>
录制终端信息并回放
查看>>
JS中window.event事件使用详解
查看>>
ES6深入学习记录(一)class方法相关
查看>>
《BI项目笔记》用Excel2013连接和浏览OLAP多维数据集
查看>>
C语言对mysql数据库的操作
查看>>
SQL Server 数据库备份
查看>>
INNO SETUP 获得命令行参数
查看>>
Charles抓取https请求
查看>>
LAMP环境搭建
查看>>
C语言的变量的内存分配
查看>>
clientcontainerThrift Types
查看>>