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 ...
随机推荐
- C#数据库发布与连接
1. 打开相关的服务 在控制面板,打开或关闭Windows特性里面,启动相关的ASP.NET相关服务,并启用IIS Manager 2. 发布应用 3. 添加应用 在Administer tools里 ...
- Python 连接MongoDB并比较两个字符串相似度的简单示例
本文介绍一个示例:使用 pymongo 连接 MongoDB,查询MongoDB中的 字符串 记录,并比较字符串之间的相似度. 一,Python连接MongoDB 大致步骤:创建MongoClient ...
- new
Android支持插件库,可以是由C/C++开发的JNI形式,也可以是由java代码开发的jar形式(也可以是android封包完成的apk文件).加载jar插件的方式可以分为 1.静态加载2.动态加 ...
- windows修改自定义格式,有的程序写的不严谨的话会造成出错,就需要重置时间格式
- mysql5.7安装(正确安装)实战
一.二进制免编译包安装 参考:http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=10105&highlight=mys ...
- I/O 流
输入流的几个常用方法: 1,复制一个文件; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; impor ...
- 第26月第8天 android studio 国内
1. //东软信息学院 mirrors.neusoft.edu.cn 80 使用方法: 启动 Android SDK Manager ,打开主界面,依次选择「Tools」.「Options…」,弹 ...
- mkyaffs2image 生成不了120M的镜像文件的解决方法
下载链接: http://download.csdn.net/download/macrocrazier/3807761 用上述下载的链接会出现Failed to execute /linuxrc ...
- java并发基础
一.创建线程 1.使用Executor:java.util.concurrent包中的执行器(Execute)为你管理Thread对象,从而简化并发编程. package thread; import ...
- Struts2基础2
一.struts中的API 1)完全解耦合的方式 1.1首先创建一个示例工程,在WEB-INF下创建lib文件夹,把struts2核心jar包导入.在工程下创建resource文件夹,并将其设为资源文 ...