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 ...
随机推荐
- StringBuilder类
java.lang.StringBuilder String类代表字符串,他的底层是一个被final修饰的数组,不能改变,字符串是常量,它们的值一旦被创建之后就不能改变,但是字符串缓冲区(String ...
- 细说java系统之动态代理
代理模式 在深入学习动态代理之前,需要先掌握代理模式.只有深刻理解了代理模式的应用,才能充分理解Java动态代理带来的便利. 在生活中存在许多使用"代理模式"的场景,比如:村里的张 ...
- 学习go语言编程系列之定义变量
package main import ( "fmt" "math") func main() { // 1. 定义变量名age,不初始化,使用对应类型的默认值 ...
- .Net结合JQuery实现向aspx后台函数进行请求。
$.ajax({ url: "Default.aspx/aaaa", async: false, type: "POST", c ...
- 【八】Spring Cloud Config
一.分布式系统面临的--配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的力度相对较小,因此系统中会出现大量的服务.由于每个服务都需要必要的配置信息才能运行,所以一套集中式的.动 ...
- tensorflow--logistic regression
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist=input_data. ...
- luogu P3722 [AH2017/HNOI2017]影魔
传送门 我太弱了,只会乱搞,正解是不可能正解的,这辈子不可能写正解的,太蠢了又想不出什么东西,就是乱搞这种东西,才能维持得了做题这样子 考虑将询问离线,按右端点排序,并且预处理出每个位置往前面第一个大 ...
- Spark思维导图之Shuffle
- JQuery属性选择
css: JQuery基本选择器: 解释 层叠选择器:
- java 基础 字符类型
1.char类型的字面量可以是一个英文字母.字符或一个汉字,并且由单引号包括. 2.Java底层使用一个16位的整数来处理字符类型,该数值是一个字符的unicode编码值. unicode: 1.un ...