链接

[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. oracle 日期格式化 TO_CHAR (datetime) 修饰语和后缀

    Datetime Format Element Suffixes Suffix Meaning Example Element Example Value TH Ordinal Number DDTH ...

  2. JDBC学习笔记之建立连接

    1. 引言 在一个JDBC应用程序中,如果想建立和数据源的连接,那么可以使用以下两个类: DriverManager:通过数据源的URL,我们可以建立与指定的数据源的连接.如果使用 JDBC 4.0 ...

  3. luogu P4781 【模板】拉格朗日插值

    嘟嘟嘟 本来以为拉格朗日插值是一个很复杂的东西,今天学了一下才知道就是一个公式-- 我们都知道\(n\)个点\((x_i, y_i)\)可以确定唯一一个最高次为\(n - 1\)的多项式,那么现在我们 ...

  4. 生成条形码插件 条形码--JsBarcode

    每天学习一点点 编程PDF电子书免费下载: http://www.shitanlife.com/code 介绍一下在GitHub生成条形码的js插件→JsBarcode 条码支持的有: CODE128 ...

  5. m100(2) 云台自动跟踪

    大疆 210云台控制 https://developer.dji.com/onboard-sdk/documentation/sample-doc/advanced-sensing-target-tr ...

  6. 什么是CSS盒模型及利用CSS对HTML元素进行定位的实现(含h5/css3新增属性)

    大家好,很高兴又跟大家见面了!本周更新博主将给大家带来更精彩的HTML5技术分享,通过本周的学习,可实现大部分的网页制作.以下为本次更新内容. 第四章 css盒模型 <!DOCTYPE html ...

  7. MyBatis原理简介和小试牛刀

    在我看来mybatis的原理与hibernate在某些方面是一致的,先回顾一下Hibernate原理(原理主要上是要掌握并理解下列六个对象: Hibernate中重要的六个对象: Configurat ...

  8. 最小生成树(图论)--3366lg【模版】

    题目描述 如题,给出一个无向图,求出最小生成树,如果该图不连通,则输出orz 输入输出格式 输入格式: 第一行包含两个整数N.M,表示该图共有N个结点和M条无向边.(N<=5000,M<= ...

  9. Spring Security 用户授权原理分析

    本文基于 spring-security-core-5.1.1 和 tomcat-embed-core-9.0.12. 本文接着Spring Security 用户认证原理分析进行分析,此时用户已完成 ...

  10. patch函数的解释1

    https://ww2.mathworks.cn/help/matlab/ref/patch.html?ue 语法 patch(X,Y,C) patch(X,Y,Z,C) patch('XData', ...