链接

[http://codeforces.com/contest/1066/problem/B]

分析

具体看代码,贪就完事了

代码

#include<bits/stdc++.h>
using namespace std; int main(){ ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,r,k,i,pos;
int a[1010];
//freopen("in.txt","r",stdin);
while(cin>>n>>r){
memset(a,0,sizeof(a));
for(i=1;i<=n;i++)
{
cin>>k;
if(k==1)//可以往两边发散的点
{
for(pos=max(1,i-r+1); pos<=min(n,r+i-1); pos++)//贪心模拟
{
a[pos]=max(a[pos],i);//所能覆盖的区域,每个位置尽可能往后贪即可
}
}
}
int ans=0;
i=1;
while(i<=n){
if(a[i]==0) {
ans=-1;
break;
}
ans++;
i=a[i]+r;//因为i这个位置最右边的覆盖点,一定可以把自己两边的区域覆盖
}
cout<<ans<<endl;
}
return 0;
}

B. Heaters Div3的更多相关文章

  1. [LeetCode] Heaters 加热器

    Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...

  2. Leetcode: Heaters

    Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...

  3. heaters

    https://leetcode.com/problems/heaters/ 开始的时候,下面的代码对于两边数字完全一样的情况,测试不通过.原因是heater会有重复情况,这时候对于飘红部分就不会往前 ...

  4. [Leetcode] Binary search -- 475. Heaters

    Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...

  5. Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)

    Problem  Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...

  6. codeforces-1144 (div3)

    赛后经验:div3过于简单,以后不做了 A.存在以下情况即为NO 1.存在相同字母 2.最大字母-最小字母 != 字符串长度 #include <map> #include <set ...

  7. [Swift]LeetCode475. 供暖器 | Heaters

    Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...

  8. LeetCode算法题-Heaters(Java实现)

    这是悦乐书的第239次更新,第252篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第106题(顺位题号是475).冬天来了!您在比赛期间的第一份工作是设计一个固定温暖半径 ...

  9. 【leetcode】475. Heaters

    problem 475. Heaters solution1: class Solution { public: int findRadius(vector<int>& house ...

随机推荐

  1. January 22nd, 2018 Week 04th Monday

    It is only when you are pursued that you become swift. 唯有在被追赶的时候,你才能真正地奔跑. It is so bad a feeling wh ...

  2. synchronized 的局限性 与 Lock 的优点

    我们已经知道,synchronized 是Java的关键字,是Java的内置特性,在JVM层面实现了对临界资源的同步互斥访问,但 synchronized 粒度有些大,在处理实际问题时存在诸多局限性, ...

  3. CSS3中和动画有关的属性transform、transition 和 animation

    CSS3中和动画有关的属性有三个  transform. transition 和 animation.下面来一一说明:        transform     从字面来看transform的释义为 ...

  4. (二 -2) 天猫精灵接入Home Assistant-自动发现Mqtt设备

    参考中文教程:  https://www.hachina.io/docs/7230.html 英文官网 两个温度传感器:https://www.home-assistant.io/docs/mqtt/ ...

  5. vue2.0 broadcast和dispatch的理解

    阅读目录 vue2 broadcast和dispatch的理解 回到顶部 vue2 broadcast和dispatch的理解 /* broadcast 事件广播 @param {componentN ...

  6. node.js 基础三 消息推送

  7. MySQL 基础四 存储过程

    -- 定义存储过程 DELIMITER // CREATE PROCEDURE query_student2() BEGIN SELECT * FROM student; END // DELIMIT ...

  8. battery for stm32

    右边两个1N4148的压降都是0.7V,并且3.3-0.7=2.6V   &   3-0.7=2.3V  可见在电源3.3V正常供电的情况下,电池处于休息状态,这就有效避免了电池的不必要消耗:

  9. ESP32 I2S

    I2S支持DMA; I2S可以直接利用DAC来输出模拟信号 (GPIO 25 & GPIO 26): 高精度时钟使能参数:   .use_apll = true ESP32配置外设一般都是配置 ...

  10. ubuntu install pip

    ubuntu 安装pip sudo apt-get update sudo apt-get upgrade sudo apt-get install python-pip