Codeforces 567D One-Dimensional Battle Ships

别再死磕Excel了!用Vensim PLE免费版,30分钟搞定你的第一个系统动力学模型 本文介绍如何使用Vensim PLE免费版在30分钟内构建第一个系统动力学模型,无需编程或数学基础。通过个人储蓄增长案例,详细讲解因果回路图绘制、存量流量图创建及方程编写,帮助读者掌握动态系统建模与仿真技巧,适用于理财、项目管理等多种场景。 阅读详情

One-Dimensional Battle Ships

题目链接:

http://codeforces.com/problemset/problem/567/D

解题思路:

First, we should understand when the game ends. It will happen when on the n-sized board it will be impossible to place k ships of size a. For segment with length len we could count the maximum number of ships with size a that could be placed on it. Each ship occupies a + 1cells, except the last ship. Thus, for segment with length len the formula will look like  (we add "fictive" cell to len cells to consider the last ship cell). This way, for [l..r] segment the formula should be .

For solving the problem we should store all the [l..r] segments which has no ''free'' cells (none of them was shooted). One could use (std: : set) for that purpose. This way, before the shooting, there will be only one segment [1..n]. Also we will store current maximum number of ships we could place on a board. Before the shooting it is equal to .

With every shoot in cell x we should find the segment containing shooted cell (let it be [l..r]), we should update segment set. First, we should delete [l..r] segment. It means we should decrease current maximum number of ships by  and delete it from the set. Next, we need to add segments [l..x - 1] and [x + 1..r] to the set (they may not be correct, so you may need to add only one segments or do not add segments at all) and update the maximum number of ships properly. We should process shoots one by one, and when the maximum number of ships will become lesser than k, we must output the answer. If that never happen, output  - 1.

AC代码:

#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

set<int> s;

int main(){
    int n,k,a,m;
    while(~scanf("%d%d%d",&n,&k,&a)){
        scanf("%d",&m);
        s.clear();
        s.insert(0);
        s.insert(n+1);
        int ans = (n+1)/(a+1);
        int ans_id = -1;
        for(int i = 1; i <= m; i++){
            int x;
            scanf("%d",&x);
            if(ans < k)
                continue;
            s.insert(x);
            set<int>::iterator it = s.find(x);
            int l = *(--it);
            int r = *(++(++it));
            ans -= (r-l)/(a+1);
            ans += (x-l)/(a+1) + (r-x)/(a+1);
            if(ans < k)
                ans_id = i;
        }
        printf("%d\n",ans_id);
    }
    return 0;
}


ALTERA MAX10 FPGA 串口远程升级实战:从原理到烧录的避坑指南 本文详细解析了ALTERA MAX10 FPGA如何通过串口实现远程升级。文章从工程师实战经验出发,深入剖析了MAX10片内Flash的双镜像备份原理、CONFIG_SEL引脚启动机制,并重点介绍了使用On-Chip Flash IP核进行擦写操作的核心流程。同时,提供了从Quartus工程配置、RPD文件生成、串口协议设计到驱动代码编写的完整避坑指南,旨在帮助开发者稳定、高效地完成远程升级功能部署。 阅读详情

相关推荐

2d游戏地图编辑器_[U3D]基于MarchingCubes实现的War3Editor 地表/悬崖编辑器

花了几天时间研究清楚Marching cubes后,发现这个方法是一个非常适用于地图编辑,网格编辑,procedural 生成的工具。最大的优点有着较好的边缘,表面处理。然后我用U3D写了一个悬崖/地表的编辑器。其中使用到了Marching Cubes的2.5D,2D两种降维的方法。talk is cheap,让我看效果!DemoEditor展示https://www.zhihu.com/vide...

weixin_42504649的博客 1191

CodeForces 567D One-Dimensional Battle Ships

题意:有一个一维线段,上面摆了k个船,每个船的长度都为a,然后有一个人来打,问你第几次攻击 就可以使得这个船无论怎么摆都不合法了 思路:一个区间合并的题,对于每一次的攻击,都只会影响到这个点所在区间,然后我们更新一下新出现的两个区间里面能摆多少个船就好了 #include using namespace std; sets; mapvis; int main() { int n

围巾的ACM博客 408

Tomcat漏洞——弱口令爆破

靶机:CentOS7 IP:192.168.100.40。攻击机:kali IP:192.168.100.60。版 权 声 明:本博客所有文章除特别声明外,均采用。文章版权归作者所有,未经允许请勿转载!作 者:PeiyuJue。

weixin_57379923的博客 920

Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships 二分 stl应用

D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice and Bob love playing o

习惯与规则决定命运 941

【软件定义汽车】-【架构篇】-全面讲解整车电子电气架构演进

前言: 前段时间,陆陆续续写了一些电子电气架构相关的文章。这里打算再写最后一篇作为收尾,为整个系列画上句号,把坑填上,这个话题就算过去了。后续一段时间,尽量把之前文章中挖的“坑”填一下。行文逻辑将借鉴5W2H进行。 另外,本文作为一篇整合性的文章,为保证逻辑的完整性,主要是将大量过去自己文章中的内容进行梳理整合,也存在很多行业内专家的公开文章的内容,请见谅。 WHAT1:什么是汽车电子电气架构? 电子电气架构:EEA,Electrical/Electronic Architecture.

零点壹客的博客 1万+

YOLOv11改进 | 集成FEM、FFM与SCAM即插即用模块:特征增强、融合与空间上下文建模新范式

FEM解决特征表达不足问题,增强关键特征响应FFM优化多尺度融合,提升小目标检测精度SCAM建模空间上下文,改善目标交互预测在保持YOLOv11实时性优势的同时,实现mAP+8.1%的显著提升,特别在复杂光照、密集目标、交互预测场景表现突出。其模块化设计使开发者可根据需求灵活组合,为各种复杂场景提供定制化解决方案。未来,随着跨模态扩展与神经架构搜索的深入,YOLOv11-FSC将进一步推动目标检测技术向更智能、更高效的方向发展。

走向CTO的路上... 995

codeforces(567D)--D. One-Dimensional Battle Ships

D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice and Bob love playing o

随风的专栏 1489

DeepFashion 服装识别:基于 YOLOv10 的深度学习实现与 UI 界面开发

随着深度学习的发展,目标检测算法在服装识别任务中表现出色,特别是 YOLO(You Only Look Once)系列模型。服装识别(Fashion Recognition)是计算机视觉领域的重要任务,广泛应用于。已提供,可用于服装分类、款式识别、虚拟试衣等应用。训练服装识别模型,并开发。

YOLO 808

CodeForces 567D One-Dimensional Battle Ships【二分】

Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a1 × n table). At the beginning of the game Alice put

mengxiang000000 867

Ubuntu零基础入门到精通【1.2讲】:Ubuntu 与 Linux 的关系 —— 你用的到底是什么?

🏆 本文收录于 《滚雪球学 Ubuntu》 专栏。 本专栏面向有一定计算机基础,但尚未系统学习 Linux / Ubuntu 的读者,采用“滚雪球式学习法”:先装好、再会用、再理解、再优化、再实战,带你从第一次进入 Ubuntu 桌面 / 终端开始,逐步掌握 Ubuntu 的日常使用、命令操作、软件安装、系统配置、开发环境搭建与服务器部署能力。

**My Coding Family** 3557

【思考模型框架】采用双钻模型:发散(桌面研究/用户访谈)→收敛(需求归类/优先级排序),输出需求规格书、追踪矩阵及产品待办清单。

设计思维双钻模型是一种以用户为中心的需求管理方法,通过"发散-收敛"的双循环确保问题定位准确、方案切实可行。第一钻石(探索→定义)聚焦"找对问题",运用用户访谈、田野调查等方法挖掘真实需求;第二钻石(开发→交付)解决"做对方案",通过原型测试、A/B测试验证可行性。该模型强调低保真验证、多团队协作和真实用户测试,避免资源浪费与伪需求开发。典型应用场景包括产品功能优化、用户体验提升等需要精准落地的需求场景。核心价值在于建立从用户痛点到解决方案的可控闭

奶爸的编程之路,也就一周冷个三天 346

CF One-Dimensional Battle Ships(set运用)

题目链接                                                            One-Dimensional Battle Ships                                     time limit per test 1 second memory limit per test 256 megabytes

换个姿势,再敲一次 565

《Autosar_MCAL高阶配置》总目录_培训教程持续更新中...

《Autosar_MCAL高阶配置》总目录_培训教程持续更新中...

「汽车电子助手」的博客 1万+

codeforces 567D. One-Dimensional Battle Ships

D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice and Bob love playing o

LJQ 745

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

【Codeforces 567D】One-Dimensional Battle Ships

【链接】 我是链接,点我呀:) 【题意】 长度为n的一个序列,其中有一些部分可能是空的,一些部分是长度为a的物品的一部分 (总共有k个长度为a的物品,一个放在位置i长度为a的物品会占据i,i+1,....i+a-1这a个格子 (物品之间必须要有至少一个空格,不能相邻 现在有一个人猜了m个不同的位置 你每次都说那个位置不是物品的一部分。(骗他) 那么请问最少在第几次你会露馅?(知道...

AWCXV 113

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

set codeforces567D One-Dimensional Battle Ships

题意:有一个长度为n的区间,现在有k个长度为a的东西,放在长度为n的区间上,且这k个东西没有重叠或接触的地方,也就是两两直接至少中间隔了一个空位 现在Bob按顺序选择了许多个点,Bob每选择一个点,Alice都会撒谎说这个点没有被覆盖,问,Bob在选了哪些点后,能确定Alice一定在说谎,也就是,在第几个点的时候,可以确定这个点一定被覆盖了 思路: ans记录上一次中区间内最多能放多

qwb的博客 874

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

[CodeForces 567D] One-Dimensional Battle Ships (区间隔断计数)

CodeForces - 567D 给定一个序列,上面有 K艘长度为 A的船互相不相邻地摆放在一起 Bob 每次都射击一个位置,Alice每次都告诉他没中 问到第几次射击的时候,可以判断出 Alice在说谎 Alice在说谎,说明射击点将区间分割成的若干个区间放不下 K艘船 一开始想着用单调队列维护了一个 DP,然后搞了些奇怪的做法,然后就 WA了事实上这题很简单,用一个 set维

MisDeer's blog 487

codeforces-567-D: One-Dimensional Battle Ships(Set | 权值线段树)

题目:http://codeforces.com/problemset/problem/567/D 题意:n个位置,k条船,每条占a个连续位置,任意两条船不能重叠或相邻,每次破坏一个位置,问破坏几次后放不下k条船。 思路:对于i条船,至少需要 i*k+ i-1 个连续的位置才可以放下,对于一段长len的连续位置有等式i*k + i-1 <= len,至多可以放(len+1)/(a+1...

A_Thinking_Reed_的博客 349

codeforces 567D One-Dimensional Battle Ships (set)

/* 题意: 在1~n的格子里,有k艘,每艘长为a的船,并且这些船不相交且不能相邻。 现在有m个射击,每个射击给你一个位置(1~n),并且不会重复。 由于对方每次都说没打中,因此你想找到至少要射击几次才能证明对方说谎。 若不能证明对方说谎,输出-1。 思路: n个格子,船长为a,则能放(n+1)/(a+1)艘船。(由于要求不能相邻,因此a+1)。 每次在set中插入射击点,二分上下界 原来可以放

苍竹林 627

One-Dimensional Battle Ships CodeForces - 567D

Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice p

码农的一亩三分地 295

【打CF,学算法——三星级】CodeForces 567D One-Dimensional Battle Ships (二分)

题目链接:CF 567D 题面: D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice and B

David_Jett 1096

codeforces 567D One-Dimensional Battle Ships (map维护)

题意: 在1~n的格子里,有k艘,每艘长为a的船,并且这些船不相交且不能相邻。 现在有m个射击,每个射击给你一个位置(1~n),并且不会重复。 由于对方每次都说没打中,因此你想找到至少要射击几次才能证明对方说谎。 若不能证明对方说谎,输出-1。 思路: n个格子,船长为a,则能放(n+1)/(a+1)艘船。(由于要求不能相邻,因此a+1)。 使用map来维护。 map[i]:维护i

642

One-Dimensional Battle Ships CodeForces - 567D

One-Dimensional Battle Ships题目描述 Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).At the b

退役的铜牌狗 516

CodeForces - 567D One-Dimensional Battle Ships —— 二分思维

D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice and Bob love playing o

Lngxling的博客 366

CodeForces - 567D One-Dimensional Battle Ships (二分)

题目链接:http://codeforces.com/problemset/problem/567/D点击打开链接 D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes input standard input

xuejye的博客 394
上一篇: Codeforces 567C Geometric Progression
下一篇: POJ 3669 Meteor Shower(bfs)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址