CF 567D(One-Dimensional Battle Ships-二分)
1 second
256 megabytes
standard input
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.
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.
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".
11 3 3
5
4 8 6 1 11
3
5 1 3
2
1 5
-1
5 1 3
1
3
1
裸二分
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
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<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;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<<ans<<endl; return 0;
}
CF 567D(One-Dimensional Battle Ships-二分)的更多相关文章
- Codeforces 567D:One-Dimensional Battle Ships(二分)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- STL(set_pair)运用 CF#Pi D. One-Dimensional Battle Ships
D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes inp ...
- 【Codeforces 567D】One-Dimensional Battle Ships
[链接] 我是链接,点我呀:) [题意] 长度为n的一个序列,其中有一些部分可能是空的,一些部分是长度为a的物品的一部分 (总共有k个长度为a的物品,一个放在位置i长度为a的物品会占据i,i+1,.. ...
- Codeforces 567D One-Dimensional Battle Ships
传送门 D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes ...
- HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)
Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is res ...
- Battle ships(二分图,建图,好题)
Battle ships Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set乱搞
D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- 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 ...
- [ZOJ 3623] Battle Ships
Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a new game which is s ...
随机推荐
- Android5.1 在init.rc 中添加自己的服务【转】
本文转载自:http://blog.csdn.net/VOlsenBerg/article/details/71085610 我有一个需求就是在Android系统开机的时候把一个配置文件放到Andro ...
- [HTML] 微信wap开发---页面自适应大小
<meta name="viewport" content="width=device-width, initial-scale=0.5, minimum-scal ...
- Python基础教程思维导图笔记
说明:直接查看图片可能不太清楚,用浏览器打开后,按住 Ctrl ,网上滚动鼠标放大浏览器页面,可以看清楚图片
- BZOJ 4547 矩阵快速幂
思路: 肯定每回只加最大值和次大值 如果 一开始的最大值>0且次大值<0 那就一直加 加到次大值>0 搞一个矩阵 推斐波那契数列 求和 就好- //By SiriusRen #inc ...
- 树莓派-基于aria2实现离线下载
安装aria2 aria2是linux下的一个下载工具,它支持http.bt种子.磁力链接三种方式下载 sudo apt-get install aria2 配置aria2 aria2支持命令参数,也 ...
- .NET中使用反射访问属性方法
.net所编写的程序集包含两个重要部分:IL(中间语言代码) 和metadata(元数据).我们编写的代码中不是有很多很多的类吗,类有很多很多的成员,在编译代码的时候,元数据表就根据代码把类的所有信息 ...
- BZOJ4518: [Sdoi2016]征途(dp+斜率优化)
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1875 Solved: 1045[Submit][Status][Discuss] Descript ...
- css3伸缩布局中justify-content详解
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 关于安卓调用wcf的一些问题
最近公司有个项目需要和别的系统做对接,对方开放的是webservice接口,搞了很久终于搞出来了,在此记录一下 获取数据的service public class SoapService implem ...
- Kafka学习笔记(5)----Kafka的Consumer
1. Pull vs Push Producer主动的通过push将消息发布到Broker上,Consumer通过Pull的的方式从Broker消息消息. 通过Push的方式由于是一有消息就推到Bro ...