一个set水 + 区间判断个数问题。。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
int L,N,a,M;
int main()
{
set<int> Pos;
set<int>::iterator it;
cin >> L >> N >> a;
{
Pos.clear();
Pos.insert(0),Pos.insert(L+1);
int ans =1 + (L - a) / (a + 1);
cin >> M;
for(int i = 1; i <= M; ++i)
{
int x;
cin >> x;
it = Pos.lower_bound(x);
int r = *it - 1;
int l = *(--it) + 1;
int len = r - l + 1;
int Sum = 0, SumR = 0, SumL = 0;
if(len >= a)
Sum = 1 + (len - a) / (a + 1);
if(x - l >= a)
SumL = 1 + (x - l - a) / (a + 1);
if(r - x >= a)
SumR = 1 + (r - x - a) / (a + 1);
ans = ans - Sum + SumL + SumR;
if(ans < N) {
cout << i << endl;
return 0;
}
Pos.insert(x);
}
cout << "-1\n";
}
return 0;
}

CF D. One-Dimensional Battle Ships的更多相关文章

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

  2. Codeforces 567D One-Dimensional Battle Ships

    传送门 D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes ...

  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. HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)

    Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is res ...

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

  6. [ZOJ 3623] Battle Ships

    Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which is s ...

  7. HDOJ 5093 Battle ships 二分图匹配

    二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...

  8. Battle ships(二分图,建图,好题)

    Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  9. ZOJ3623:Battle Ships(全然背包)

    Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...

  10. ZOJ 3623 Battle Ships DP

    B - Battle Ships Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

随机推荐

  1. Oracle和Mysql的安装

    Oracle12C的安装:https://blog.csdn.net/qubeleyz/article/details/79451192 Mysql安装:

  2. git 提交解决冲突(转载)

    转载 git 提交解决冲突 http://www.cnblogs.com/qinbb/p/5972308.html   一:git命令在提交代码前,没有pull拉最新的代码,因此再次提交出现了冲突. ...

  3. SQL Server进阶 遍历表的几种方法

    https://www.cnblogs.com/mcgrady/p/4182486.html

  4. UDP客户/服务器程序所用的套接字函数

  5. 【51nod 1100】斜率最大

    Description 平面上有N个点,任意2个点确定一条直线,求出所有这些直线中,斜率最大的那条直线所通过的两个点.   (点的编号为1-N,如果有多条直线斜率相等,则输出所有结果,按照点的X轴坐标 ...

  6. ie8 background背景图片不显示问题

    在chrome,FF可以显示,但是在ie8背景图片显示不出来 css改为如下可以正常显示: background: url(../images/goods.png) no-repeat !import ...

  7. c# cbo控件

    c#  cbo控件 ,要获取选中的值 最好使用 ((强转的类型)selectitem).属性

  8. 基础的POJ学习

    OJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 初期: 一. ...

  9. 源码学习之mybatis

    1.先看看俩种调用方式 public static void main(String[] args) { SqlSessionFactory sqlSessionFactory; SqlSession ...

  10. apache基础学习

    1,apache是什么? 目前最主流的三个Web服务器是Apache Nginx IIS 2,环境搭建 linux系统安装xampp: 先下载xampp for linux,放在/opt文件夹下,程序 ...