思路:

从左向右贪心选择能覆盖当前位置的最靠右的那个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. HDU1074(状态压缩DP)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bireportSqlSessionFactory' defined in URL

    报错如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'birepo ...

  3. Makefile研究(二)—— 完整可移植性模板

    转自:http://blog.csdn.net/jundic/article/details/17676461 一直想写一个很全很好移植的Makefile模板,我觉得一个完整makefile 应该包含 ...

  4. JAVA基础--JAVA API常见对象(包装类和正则)12

    一.基本类型包装类 1.基本类型包装类介绍 8种基本类型: byte  short    int    long    float   double   char   boolean 这8种基本类型它 ...

  5. Warning: The Copy Bundle Resources build phase contains

    在编译程序时,遇到了这样的Waring:   Warning: The Copy Bundle Resources build phase contains this target's Info.pl ...

  6. Unity3d 3d角色换装实现原理及步骤

    http://www.cnblogs.com/dosomething/archive/2012/04/15/2450526.html 1.角色模型制作 unity3d支持Skin动画  但是不支持Ph ...

  7. poj2133(sg函数)

    关于sg函数:http://www.cnblogs.com/Knuth/archive/2009/09/05/1561007.html 题目链接:http://poj.org/problem?id=2 ...

  8. 第四章 “我要点爆”微信小程序云开发之疯狂点击与糖果点爆页面制作

    疯狂点击点爆方式页面制作 疯狂点击为用户提供一个60秒的按钮点击时间,同时点击过程中有背景音乐,系统根据用户点击按钮的此时来进行热度值的计算. <view class="the_hea ...

  9. Mysql 主从(转)

    转自 http://blog.csdn.net/hguisu/article/details/7325124

  10. Android近场通信---NFC基础(五)(转)

    转自 http://blog.csdn.net/think_soft/article/details/8190463 Android应用程序记录(Android Application Record- ...