CF D. One-Dimensional Battle Ships
一个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的更多相关文章
- 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
传送门 D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes ...
- 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 ...
- HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)
Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is res ...
- 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 ...
- HDOJ 5093 Battle ships 二分图匹配
二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...
- Battle ships(二分图,建图,好题)
Battle ships Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- ZOJ3623:Battle Ships(全然背包)
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...
- ZOJ 3623 Battle Ships DP
B - Battle Ships Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
随机推荐
- extjs.net 按钮执行并显示Mask代码
<ext:Button ID="ButtonTest" runat="server" Width="65" Text="同 ...
- getaddrinfo函数
一.功能 对于IPv4和IPv6均适用,可以处理名字到地址以及服务到端口这两种变换,返回的是一个sockaddr结构而不是一个地址队列 二.函数原型 #include <netdb.h> ...
- 图像分类中max-pooling和average-pooling之间的异同
池化操作时在卷积神经网络中经常采用过的一个基本操作,一般在卷积层后面都会接一个池化操作,但是近些年比较主流的ImageNet上的分类算法模型都是使用的max-pooling,很少使用average-p ...
- [C++]数值与字符串转换问题
#include <stdio.h>//sprintf #include <stdlib.h>//atof,atol,strtod,strtol using namespace ...
- vue Transfer 穿梭框
Element Transfer组件默认支持单个list的穿梭 现业务需要支持两个list,效果如下 实现思路: 1.有选中才可穿梭 2.已穿梭源数据减少.目标增加(双向) 边界条件: 存储旧List ...
- bind,unbind,one
刚开始我们先看一下它的定义: .bind( eventType [, eventData], handler(eventObject)) .Bind()方法的主要功能是在向它绑定的对象上面提供一些事件 ...
- 个人经验~mongo故障处理思路
一 简介:mongodb 应该如何排查二 分析角度 linux 角度 1 硬件是否有问题 常见主板 raid卡 和raid磁盘组 2 综合指标 负载 uptime : 1min 5mi ...
- Redis 集群环境的搭建
下载与解压 [root@localhost ~]# cd /usr/temp/ [root@localhost temp]# wget http://download.redis.io/release ...
- scrapy基础 之 爬虫入门:先用urllib2来理解爬虫
1,概念理解 爬虫:抓取和保存网页信息,用户看到的网页实质是由 HTML 代码构成的,爬虫爬来的便是这些内容,通过分析和过滤这些 HTML 代码,实现对图片文字等资源的获取. URL:即统一资源定位符 ...
- /bin/bash^M: bad interpreter: No such file or directory 解决办法
参考:-bash: ./my_script: /bin/bash^M: bad interpreter: No such file or directory [duplicate] 有的时候运行.sh ...