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 ...
随机推荐
- 在iOS开发中,我们会遇到十六进制和字符串之间相互转换,话不多说,直接上代码:
//将十六进制的字符串转换成NSString则可使用如下方式: + (NSString *)convertHexStrToString:(NSString *)str { if (!str || [s ...
- (hdoj 5137 floyd)How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- B1012 [JSOI2008]最大数maxnumber 分块||RMQ
这个题有毒,卡最大值...我开1 << 30爆零让我以为我分块错了...gg,然后去写RMQ,但是这个题st表是真简单啊.后来刘胜与巨佬一眼看出来我最大值不够大...然后1LL<&l ...
- linux Redis 5.0集群搭建
文档结构如下: Redis cluster 是redis的分布式解决方案,在3.0版本正式推出后,有效的解决了redis分布式方面的需求:当遇到单机内存,并发,流量等瓶颈是,可以采用cluster架构 ...
- DDL:对表___table___的相关操作
1) 增加列 语法: alter table 表名 add 列名 类型(长度) 约束; 2) 修改现有列类型.长度和约束 语法:alter table 表名 modify 列名 类型(长度) 约束; ...
- SqlServer显示“正在还原...”
还原数据库时,提示还原成功,但是数据库一直显示“正在还原...”的状态. 可以通过执行以下命令即可 RESTORE DATABASE DB_NAME WITH RECOVERY 原因: 关于recov ...
- 装饰模式(Decorator)C++实现
装饰模式 层层包装,增强功能.这就是装饰模式的要旨!装饰器模式就是基于对象组合的方式,可以很灵活的给对象添加所需要的功能.它把需要装饰的功能放在单独的类中,并让这个类包装它所要装饰的对象. 意图: 动 ...
- mybatis学习笔记之基础框架(2)
mybatis学习笔记之基础框架(2) mybatis是一个持久层的框架,是apache下的顶级项目. mybatis让程序将主要精力放在sql上,通过mybatis提供的映射方式,自由灵活生成满足s ...
- Android横屏时软键盘全屏问题
1.使用 SearchView xml加入 android:imeOptions="actionDone|flagNoExtractUi" 可以限制软键盘禁止全屏 <andr ...
- APP开发中,如何从UI设计上提升APP用户体验
设计中有很多细微的东西要注意,就如UI设计中,元素的统一性,图标风格.段落的排版等等,只有能注意这些细节,你的 APP UI 才算合格. 干货君总结了17个提升用户体验的 UI 设计小技巧,也是我们日 ...