思路:

从左向右贪心选择能覆盖当前位置的最靠右的那个heater即可,和poj radar installation类似。

实现:

 #include <iostream>
#include <cassert>
using namespace std; const int INF = 0x3f3f3f3f; int a[], cov[]; int main()
{
int n, r;
while (cin >> n >> r)
{
fill(cov + , cov + n + , -);
for (int i = ; i <= n; i++) cin >> a[i];
for (int i = ; i <= n; i++)
{
for (int j = max(, i - r + ); j <= min(n, i + r - ); j++)
{
if (a[j] == ) cov[i] = j;
}
}
int maxn = -INF, cnt = ;
bool flg = true;
for (int i = ; i <= n; i++)
{
if (maxn >= i - r + && maxn <= i + r - ) continue;
else if (cov[i] == -) { flg = false; break; }
else
{
maxn = cov[i];
cnt++;
}
}
cout << (flg ? cnt : -) << endl;
}
return ;
}

CF1066B Heaters的更多相关文章

  1. CF1066B Heaters(贪心)

    题意描述: Vova先生的家可以看作一个n×1的矩形,寒冷的冬天来了,Vova先生想让他的家里变得暖和起来.现在我们给你Vova先生家的平面图,其中111表示这个地方是加热炉,0表示这个地方什么也没有 ...

  2. [LeetCode] Heaters 加热器

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

  3. Leetcode: Heaters

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

  4. heaters

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

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

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

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

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

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

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

  8. 【leetcode】475. Heaters

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

  9. 475. Heaters

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

随机推荐

  1. Java笔记(七)

    File类: import java.io.File; import java.io.IOException; public class Demo{ public static void main(S ...

  2. HiddenHttpMethodFilter

    操作步骤: 在web.xml中配置: 删除操作: 其他操作即为将DELETE换成INPUT/POST/GET

  3. B - Equidistant String

    B - Equidistant String Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & % ...

  4. CodeForces Gym 100685I Innovative Business (贪心)

    题意:给定一条路的长和宽,然后给你瓷砖的长和宽,你只能横着或者竖着铺,也可以切成片,但是每条边只能对应一条边,问你最少要多少瓷砖. 析:先整块整块的放,然后再考虑剩下部分,剩下的再分成3部分,先横着, ...

  5. 您的Microsof Internet Explorer浏览器包含新版本的内置Adobe Flash Player。

    win8 安装adobe flash player时错误提示: 您的Microsof Internet Explorer浏览器包含新版本的内置Adobe Flash Player. 感谢达人提供了如下 ...

  6. Android NDK开发指南(二)Android.mk文件

    http://www.cnblogs.com/yaozhongxiao/archive/2012/03/06/2382225.html 1.  概述 Android.mk文件是用来描述build sy ...

  7. XHTML学习笔记 Part2:核心元素

    1. <html>元素 <html xmlns="http://www.w3.org/1999/xhtml"> 仅有两个元素是<html>的直接 ...

  8. 新手安装 hadoop、hive和hbase 笔记

    系统是ubuntu 12.04 , hadoop版本是1.2.1 , hive版本是0.12 , hbase版本我忘记了,不好意思首先是配置好hostnamevi /etc/hosts写入你要配置的i ...

  9. github的上传本地文档

    自从使用github以来,一直都是在github网站在线上传文件到仓库中,但是有时因为网络或者电脑的原因上传失败.最重要的原因是我习惯本地编辑,完成以后再一起上传github.看过了几个教程,总结出最 ...

  10. JAVA列出某文件夹下的所有文件

    import java.io.*; public class ListFiles { private static String s = ""; private static Bu ...