『ACM C++』 Codeforces | 1066B - Heaters
今日不写日感,直接扔上今日兴趣点:
新研究称火星曾经有一个巨大的地下水系统
链接:https://mbd.baidu.com/newspage/data/landingsuper?context=%7B"nid"%3A"news_6959868648919860397"%7D&n_type=0&p_from=1
------------------------------------------------题目----------------------------------------------------------
Heaters
Vova's house is an array consisting of nn elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The ii-th element of the array is 11 if there is a heater in the position ii, otherwise the ii-th element of the array is 00.
Each heater has a value rr (rr is the same for all heaters). This value means that the heater at the position pospos can warm up all the elements in range [pos−r+1;pos+r−1][pos−r+1;pos+r−1].
Vova likes to walk through his house while he thinks, and he hates cold positions of his house. Vova wants to switch some of his heaters on in such a way that each element of his house will be warmed up by at least one heater.
Vova's target is to warm up the whole house (all the elements of the array), i.e. if n=6n=6, r=2r=2 and heaters are at positions 22 and 55, then Vova can warm up the whole house if he switches all the heaters in the house on (then the first 33 elements will be warmed up by the first heater and the last 33 elements will be warmed up by the second heater).
Initially, all the heaters are off.
But from the other hand, Vova didn't like to pay much for the electricity. So he wants to switch the minimum number of heaters on in such a way that each element of his house is warmed up by at least one heater.
Your task is to find this number of heaters or say that it is impossible to warm up the whole house.
Input
The first line of the input contains two integers nn and rr (1≤n,r≤10001≤n,r≤1000) — the number of elements in the array and the value of heaters.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10≤ai≤1) — the Vova's house description.
Output
Print one integer — the minimum number of heaters needed to warm up the whole house or -1 if it is impossible to do it.
Examples
input
output
input
output
input
output
-
input
output
Note
In the first example the heater at the position 22 warms up elements [1;3][1;3], the heater at the position 33 warms up elements [2,4][2,4] and the heater at the position 66 warms up elements [5;6][5;6] so the answer is 33.
In the second example the heater at the position 11 warms up elements [1;3][1;3] and the heater at the position 55 warms up elements [3;5][3;5] so the answer is 22.
In the third example there are no heaters so the answer is -1.
In the fourth example the heater at the position 33 warms up elements [1;5][1;5], the heater at the position 66 warms up elements [4;8][4;8] and the heater at the position 1010 warms up elements [8;10][8;10] so the answer is 33.
------------------------------------------------题目----------------------------------------------------------
(一) 原题大意:
有n个位置顺序排列。可以在某些位置放置灯光。假设x位置放置了一个灯光,这样位置在[x-r+1,x+r-1]范围内的所有位置都可以被灯光的光辉照亮
所有位置都想要被照亮,请问要至少多少个灯?
注:无解的话输出-1。
输入的第一行包含两个整数n和r(1≤n,r≤1000) - 位置的个数和灯光光线半径。
第二行包含n个整数a1,a2,...,(0≤ai≤1) - ai=1代表该位置可以放灯光,但不一定有必要。
最后打印一个整数 - 至少要放的灯光个数,如果不可能照亮所有位置,则为-1。
『ACM C++』 Codeforces | 1066B - Heaters的更多相关文章
- 『ACM C++』 Codeforces | 1066A - Points in Segments
大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...
- 『ACM C++』 Codeforces | 1005D - Polycarp and Div 3
今天佛了,魔鬼周一,在线教学,有点小累,但还好,今天AC了一道,每日一道,还好达成目标,还以为今天完不成了,最近任务越来越多,如何高效完成该好好思考一下了~最重要的还是学业的复习和预习. 今日兴趣新闻 ...
- 『ACM C++』 Codeforces | 1003C - Intense Heat
今日兴趣新闻: NASA 研制最强推进器,加速度可达每秒 40 公里,飞火星全靠它 链接:https://mbd.baidu.com/newspage/data/landingsuper?contex ...
- 『ACM C++』 PTA 天梯赛练习集L1 | 007-011
真的是忙头晕了,学业.ACM打题.班级活动.自学新东西,哇这充实的大学~ ------------------------------------------------L1-007--------- ...
- 『ACM C++』HDU杭电OJ | 1418 - 抱歉 (拓扑学:多面体欧拉定理引申)
呕,大一下学期的第一周结束啦,一周过的挺快也挺多出乎意料的事情的~ 随之而来各种各样的任务也来了,嘛毕竟是大学嘛,有点上进心的人多多少少都会接到不少任务的,忙也正常啦~端正心态 开心面对就好啦~ 今天 ...
- 『ACM C++』HDU杭电OJ | 1425 - sort (排序函数的特殊应用)
今天真的是累哭了,周一课从早八点半一直上到晚九点半,整个人要虚脱的感觉,因为时间不太够鸭所以就回头看看找了一些比较有知识点的题来总结总结分析一下,明天有空了就开始继续打题,嘻嘻嘻. 今日兴趣电影: & ...
- 『ACM C++』HDU杭电OJ | 1415 - Jugs (灌水定理引申)
今天总算开学了,当了班长就是麻烦,明明自己没买书却要带着一波人去领书,那能怎么办呢,只能说我善人心肠哈哈哈,不过我脑子里突然浮起一个念头,大二还要不要继续当这个班委呢,既然已经体验过就可以适当放下了吧 ...
- 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester
这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...
- 『ACM C++』PTA浙大 | 基础题 - 打印沙漏
<数据结构>开课前的一些小作业练习,可能因为一个寒假都没有打C++手生了,整个寒假都在帮拍电影做后期特效,导致这道题居然用了两个钟去AC,深感惭愧,作个标记吧,下面上题. 一首好曲推荐:同 ...
随机推荐
- git 命令收藏
git init # 初始化本地git仓库(创建新仓库) git config --global user.name "xxx" # 配置用户名 git config -- ...
- vue支付密码
从网上搜索了好多都很麻烦,花了点事件自己做了个,简单轻便,老少皆宜 <template> <section class="pay-mask" @click=&qu ...
- 在IIS中浏览网站时出现:无法打开登录所请求的数据库 "***",登录失败
在IIS中发布Web应用程序后,浏览网站时出现无法打开登录所请求的数据库 "***",登录失败错误,如下图所示: 解决办法:打开系统Web.Config配置文件,查看数据库连接串是 ...
- ArcGIS DataStore手册——常见问题篇
第三章:ArcGIS DataStore常见问题处理 1.DataStore使用的数据库是什么? 从安装后的内容和配置完DataStore中Server Manager中的信息来看,DataStore ...
- ArcGIS Server 10.1发布要素服务(FeatureLayer server)时遇到的数据库注册问题
在发布要素服务的最后一步遇到了一个问题: SEVERITY STATUS CODE DESCRIPTION NAME TYPE DATA FRAME High Unresolved 00090 Fea ...
- Porting QML Applications to Qt 5
When porting QML-related code from Qt 4.8 to Qt 5, application developers should be aware that the Q ...
- git下的团队合作模型及git基础知识汇集
https://www.atlassian.com/git/tutorials/syncing/git-fetch Syncing svn使用单个中央库来作为开发者之间沟通的桥梁,而协同合作是通过在开 ...
- Less的guards and argument matching
less guards/argument matching: .setbackground(@number) when (@number>0){ .setbackground( @number ...
- QT的mouseMoveEvent事件失效
void TalkWindow::enterEvent(QEvent *event){ grabMouse();}void TalkWindow::leaveEvent(QResizeEvent *e ...
- C++ 类的存储方式以及虚函数表
一.C++成员函数在内存中的存储方式 用类去定义对象时,系统会为每一个对象分配存储空间.如果一个类包括了数据和函数,要分别为数据和函数的代码分配存储空间.按理说,如果用同一个类定义了10个对象,那么就 ...