思路:

从左向右贪心选择能覆盖当前位置的最靠右的那个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. 自已封装Ajax方法

    function createXHR() { var request; if (typeof (XMLHttpRequest) == 'undefined') { request = new Acti ...

  2. 开源跨平台声波传输库:Sonic

    简介 [Sonic](https://github.com/linyehui/sonic) 是一个跨平台的声波传输库(iOS & Android),技术上类似于[chirp](http://c ...

  3. VS2008编了个MFC对话框,编译链接都没有问题,但是运行出来的对话框完全不能点击

    误将整个对话框的属性中disable选为“True”,对话框不可用,选为false即可

  4. 各浏览器userAgent汇总

    浏览器  navigator.userAgent  备注  IE6  Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)   IE7  Mo ...

  5. 高级java工程师面试题-随笔

    最近打算要换工作,也面试了几家,因为不是自己喜欢的所以拒了一些(当然也有人家不要我的.....).在面试的过程中发现对java高级程序员的考察基本上围绕知识面,知识深度两个方面来考察.下面是在面试过程 ...

  6. Spring boot实例

    代码下载http://pan.baidu.com/s/1c2aXLkc 密码:2joh 1.代码包规划 Application主类 package com.smart; import org.spri ...

  7. wmware7安装xp错误:虚拟CPU已经入关闭状态

    wm7安装xp错误提示: 虚拟CPU已经入关闭状态.这会造成物理计算机重新启动.这可能是虚拟机操作系统的错误或VMware Workstation软件中的一个配置不正确. 这种情是硬盘模式为AHCI模 ...

  8. HDU - 2612 Find a way 双起点bfs(路径可重叠:两个队列分别跑)

    Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. Linux whereis 搜索命令位置

    在学习 兄弟连 linux教学视频 的时候,我将所学的 linux 命令记录在我的博客中,方便自己查阅. 文件搜索命令: whereis 基础的命令 命令名称:whereis 命令的所在路径:/usr ...

  10. [Swift 开发] 使用闭包传值(typealias)

    在Swift中使用闭包来实现两个界面的传值 例如:有A类和B类. B类 //声明闭包 typealias valueBlock = (Float)->() var returnPrice: va ...