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 ...
随机推荐
- Structured Streaming Programming Guide结构化流编程指南
目录 Overview Quick Example Programming Model Basic Concepts Handling Event-time and Late Data Fault T ...
- VM克隆后找不到eth0的问题解决
问题描述 使用VM WorkStation新建虚拟机A,查看IP信息,显示结果: [root@centos65x64 ~]# ifconfig -a eth0 Link encap:Ethernet ...
- vim学习之git for windows
这是我在博客园的第二篇文章,今晚是在线的特殊日子,应小编的要求不想多讲,喝了点酒,感觉到压力和挑战性,抽了几根烟,现在有点飘飘欲仙的感觉.在长江大学11教的6楼,是长大在线的办公室,这个晚上总是不关灯 ...
- Chimee - 简单易用的H5视频播放器解决方案
Chimee是由奇舞团开源的一套H5视频播放器解决方案,由奇舞团视频云前端团队结合在业务和视频编解码方向的沉淀积累倾心打造.Chimee支持MP4.M3U8.FLV等多种媒体格式,同时它也帮我们解决了 ...
- a*寻路分析
http://dev.gameres.com/Program/Abstract/Arithmetic/A%20Pathfinding%20for%20Beginners.htm 定义: 绿色节点为A ...
- linux 普通用户下使用 jdk 、Tomcat
需求: 在已经跑的 1.7java环境中需要跑1.8java环境所需要的tomcat,那么因为java环境的不同,nginx代理会出现很多问题,tomcat根本跑不起来,所以提供了以下解决方案. 一, ...
- 洛谷 P1032 【字串变换】
感觉这个题用一些常用的stl和string函数会非常简单..(难道就是考这两个的吗? vector<pair<string,string>>pos//用于变化 map<s ...
- Python文件打包成exe
1. 安装pyinstaller pip install pyinstaller 2.如果有外部依赖包 将外部依赖包放到你的python安装的site-packages D:\Python27\Lib ...
- Python 爬虫五 进阶案例-web微信登陆与消息发送
首先回顾下网页微信登陆的一般流程 1.打开浏览器输入网址 2.使用手机微信扫码登陆 3.进入用户界面 1.打开浏览器输入网址 首先打开浏览器输入web微信网址,并进行监控: https://wx.qq ...
- RabbitMQ简单应用の公平分发(fair dipatch)
公平分发(fair dipatch)和轮询分发其实基本一致,只是每次分发的机制变了,由原来的平均分配到现在每次只处理一条消息 1.MQ连接工厂类Connection package com.mmr.r ...