CF1066B Heaters
思路:
从左向右贪心选择能覆盖当前位置的最靠右的那个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的更多相关文章
- CF1066B Heaters(贪心)
题意描述: Vova先生的家可以看作一个n×1的矩形,寒冷的冬天来了,Vova先生想让他的家里变得暖和起来.现在我们给你Vova先生家的平面图,其中111表示这个地方是加热炉,0表示这个地方什么也没有 ...
- [LeetCode] Heaters 加热器
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...
- Leetcode: Heaters
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...
- heaters
https://leetcode.com/problems/heaters/ 开始的时候,下面的代码对于两边数字完全一样的情况,测试不通过.原因是heater会有重复情况,这时候对于飘红部分就不会往前 ...
- [Leetcode] Binary search -- 475. Heaters
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...
- [Swift]LeetCode475. 供暖器 | Heaters
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...
- LeetCode算法题-Heaters(Java实现)
这是悦乐书的第239次更新,第252篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第106题(顺位题号是475).冬天来了!您在比赛期间的第一份工作是设计一个固定温暖半径 ...
- 【leetcode】475. Heaters
problem 475. Heaters solution1: class Solution { public: int findRadius(vector<int>& house ...
- 475. Heaters
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
随机推荐
- Spring 事务管理高级应用难点剖析: 第 3 部分
本文是“Spring 事务管理高级应用难点剖析” 系列文章的第 3 部分,作者将继续深入剖析在实际 Spring 事务管理应用中容易遇见的一些难点,包括在使用 Spring JDBC 时如果直接获取 ...
- springmvc配置一:ajax请求防止返回中文乱码配置说明
Spring3.0 MVC @ResponseBody 的作用是把返回值直接写到HTTP response body里. Spring使用AnnotationMethodHandlerAdapter的 ...
- HDU2159(完全背包)
FATE Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description ...
- 2.3-2.6 HBase java API
一.get .put.delete.scan 1.代码 package com.beifeng.senior.hadoop.hbase; import org.apache.hadoop.conf.C ...
- Flutter实战视频-移动电商-02.Flutter实战建立项目和编写入口文件
02.Flutter实战建立项目和编写入口文件 创建项目: flutter create flutter_shop 创建完成之后呢,它会提示我们, 进入flutter_shop的目录,然后执行flut ...
- Identity Server 4 原理和实战(完结)_为 MVC 客户端刷新 Token
服务端修改token的过期使劲为60秒 过期了 仍然还能获取到api1的资源 api1,设置每隔一分钟就验证token 并且要求token必须要有超时时间这个参数, 1分钟后提示超时,两边都是一分钟, ...
- 使用git命令将本地项目上传到GIthub
1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 2.把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点“.”,意为添加文 ...
- 为何在有 DOCTYPE 的 HTML 文档之上仍然还会出现混杂模式?
不使用 DOCTYPE 一定会使 HTML 文档处于混杂模式,然而使用了 DOCTYPE,也不一定就能够使文档在所有浏览器中均处于标准模式. DOCTYPE 本身不就是一个“开关”吗?为何在有 DOC ...
- E20190212-mt
创建: 2019/02/12 reserve n. 储备; 保留; 保护区; 替补队员; vt. 储备; 保留; 预约; vi. 预订; slot n. 位置; 狭槽,水沟; [人名] ...
- 201621123016 《Java程序设计》第十三周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 为你的系统增加网络功能(购物车.图书馆管理.斗地主等)-分组完成 为了让你的系统可以被多个用户通过网 ...