题目的意思是:

如今有一个长度为n,宽为1的方格,在上面能够放大小为1*a船,然后输入为n,k,a。分别为平地的大小,船的数量,船的长度。

一个叫alice的人已经在地图上摆好了船的位置。

然后bob总共能够有m次攻击的机会,然后他每次攻击的点为xi。可是alice并不会告诉它有没有打中(也就是说每次都觉得他是miss的)。问你,bob能够在第几次攻击的时候猜測出alice在撒谎,假设猜測不出来则输出-1.

这里每两条相邻的船不能相互接壤。

思路:

用set来维护每一段的区间。

首先。我们最多能够放sum=(n+1)/(a+1)条船。

这个公式是怎么来的呢? 我们能够这样想: 由于船不能接壤。所以当有k条船时,n最少为k*(a+1)-1;  然后反解就能得到答案了。

然后我们每次攻击一个点t,就相当于把线段从中间隔开来了,我们要找到离点t近期的左右端点t1,t2,由于它们中间还插了一个t,所以就相当于t1,t2被切割开来了。

然后当前船的数量能够由还有一个公式得到: sum=sum-(t2-t1)/(a+1)+(t-t1)/(a+1)+(t2-t)/(a+1) ;这里的意思就相当于把原先的那个区间的部分减掉,然后再加上后来分开来后的区间所能容纳的船的最大数目。

当sum<k的时候,就说明此时alice在撒谎。

这里查找左右端点用的是二分查找。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define me rng_58
#define maxn 200055
set<int> st;
set<int>::iterator it;
int main(){
int n,k,a,m,i;
scanf("%d%d%d",&n,&k,&a);
scanf("%d",&m);
st.insert(0);
st.insert(n+1);
int sum=(n+1)/(a+1);
int ans=-1;
for(i=1;i<=m;i++){
int t;
scanf("%d",&t);
it=st.upper_bound(t);
int t1=*it;
it--; //这里为什么能减。学c++后再解答;
int t2=*it;
st.insert(t); //这里仅仅要把t压进去就好啦!! !小心!。! sum=sum-(t1-t2)/(a+1)+(t-t2)/(a+1)+(t1-t)/(a+1);
if(sum<k){
ans=i;
break;
}
}
printf("%d\n",ans);
}
/*
5000 1660 2
20
1 100 18 102 300 81 19 25 44 88 1337 4999 1054 1203 91 16 164 914 1419 1487
*/

佩服那些可以想出来的人。Wish I can become the same like U one day!

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

  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: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  4. 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 ...

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

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

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

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

  7. 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 ...

  8. 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 ...

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

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

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

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

随机推荐

  1. bash脚本输入密码不回显问题的解决方法

    编写一个bash脚本时,需要用户输入一个密码,方可继续后续流程,但是又要保证用户输入的密码不会被别人看到,因此排除了通过参数将密码传入脚本的方案 不绕圈子,揭晓答案:设置终端状态为“字符不回显”(如果 ...

  2. Amoeba软件实现mysql读写分离

    一般不用,大公司都是自己程序实现的. 安装amoeba

  3. laravel 拾遗 中间件

    Problem You want to add middleware to your application but don't know where to begin.     Solution C ...

  4. electron 的跳转

    // 测试 正常跳转应该登录成功 // that.timer = setInterval(() => { that.$router.push('/mainChat');//路由跳转mainCha ...

  5. Punycode转中文

    package cn.cnnic.ops.udf; public class GetChineseFromPunycode { static int TMIN = 1; static int TMAX ...

  6. html5和css3学习历程

    1.video,audio视频和音频的应用 <!doctype html><html> <head></head> <body>  < ...

  7. c++构造函数中调用构造函数---匿名对象再探

    #include<iostream> #include<string> using namespace std; class Copy_construction { publi ...

  8. iosttableViewCell右侧的箭头,圆形等

    cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式 cell.accessoryType = UITableViewCell ...

  9. 基于jQuery在线问卷答题系统代码

    分享一款基于jQuery在线问卷答题系统代码是一款实用的jQuery答题插件,点击下一题切换带有淡入淡出效果.实现的效果图如下: 在线预览   源码下载 实现的代码. html代码: <div ...

  10. SQL Injection绕过技巧

    0x00 sql注入的原因 sql注入的原因,表面上说是因为 拼接字符串,构成sql语句,没有使用 sql语句预编译,绑定变量. 但是更深层次的原因是,将用户输入的字符串,当成了 "sql语 ...