一个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. python --端点调试

    python端点调试 左边三角:快速跳到下一个端点 下箭头:单不调试 斜向下箭头:跳到函数内部执行代码

  2. spring中整合memcached,以及创建memcache的put和get方法

    spring中整合memcached,以及创建memcache的put和get方法: 1:在项目中导入memcache相关的jar包 2:memcache在spring.xml的配置: 代码: < ...

  3. [Android] Android v4包CompoundButtonCompatLollipop.class重复问题

    用 Butter Knife  8.8.1  导致v4包CompoundButtonCompatLollipop.class重复问题 详细错误如下: Error:Execution failed fo ...

  4. Android中的分层----service 层,domain层,dao 层,action层等设计

    service 层 服务层:直接为客户端提供的服务或功能.也是系统所能对外提供的功能. domain层 领域层:系统内的领域活动,存放实体. dao 层 持久层,DB操作都写在这里,数据访问对象,通过 ...

  5. 账号管理文件/etc/passwd和/etc/shadow

    /etc/passwd和/etc/shadow是Linux中两个账号管理的重要文件 一./etc/passwd        这个文件中每一行代表一个账号,有几行就代表系统中存在几个账号.有些账号是系 ...

  6. oracle rman备份

    rman 登录到cmd 打开cmd 输入 rman connect target jhpt/1@orcl C:\Documents and Settings\Administrator>rman ...

  7. Git配置信息相关命令

    查看git所有配置项 $ git config -l or $ git config --list 全局配置用户名邮箱 $ git config --global user.name "yo ...

  8. python 的基础 学习 第五天 基础数据类型的操作方法

    1,列表的基本操作方法 1,列表是python中的基础数据类型之一,其他语言中也有类似于列表的数据类型,比如js中叫数组,他是以[ ]括起来,每个元素以逗号隔开,而且他里面可以存放各种数据类型比如: ...

  9. jstl-----之<set>标签

    <table id="attachtab" border="0" cellpadding="0" cellspacing=" ...

  10. Lr-代理录制

    哈哈,第一讲,决定分享一下代理的一些知识,是我学习的总结,可能会有错误,欢迎大家指正. 问题一:代理录制是为了解决什么问题或者说为什么么要使用代理呢? 这是因为lr只能使用IE浏览器进行录制,如果想使 ...