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 ...
随机推荐
- [ZJOI 2007] 捉迷藏
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1095 [算法] 首先建出点分树,然后每一个点开两个堆.“第一个堆记录子树中所有节点到 ...
- javascript之创建对象的方式
1.object构造函数创建 var obj=new Object(); obj.name='xue'; 2.对象字面量创建 var obj={ name:'xue' } 3.构造函数创建 funct ...
- Tinyplay
android里面的目录:external/tinyalsa 编译: 1. cd external/tinyalsa/ 2. vi Android.mk 3. mmm . 4. 拷贝出可执行文件 执行 ...
- 解决向github提交代码不用输入帐号密码
解决方案:方案一: 在你的用户目录下新建一个文本文件.git-credentials Windows:C:/Users/username Mac OS X: /Users/username Linux ...
- Firebug 的脚本页面不能用
1.遇到这种情况,一般重置firebug,然后开启“脚本“功能,刷新页面,就能显示正常 2.要不就是 版本问题,50.0不行,下载回49版本就可以了
- 【222】◀▶ IDL 输入输出函数说明
参考:I/O - General Input/Output Routines —— 基本输入输出函数 01 PRINT/PRINTF 格式化输出. 02 READ/READF 格式化输入. 0 ...
- 红帽系统制作yum本地源
1 首先得吐槽吐槽,机房冷就算了,不能用手机(哈哈你懂的),没有站的位置,显示屏看不清楚.就这样开始制作yum本地源. 2 记下注意得两点,以防以后会忘记 a:可能是因为红帽系统,加上是实用光盘挂载的 ...
- ubuntu的 mysql 存储目录迁移
1:sudo service MySQL stop#迁移前必须先停止mysql 2:创建mysql 存放的 目标文件夹 一般 默认的 mysql 存储目录在 /var/lib中 看清楚 文件的权限 ...
- HDU - 2037 今年暑假不AC 贪心(求序列中不重叠子序列的最大值问题)
HDU2037 今年暑假不AC 贪心算法 大意: 每次测试数据输入一个n,然后输入n对的电视节目播放时间:开始时间及结束时间, 求这个人能看的最多的完整的节目数. 解题思路: 对于这道解题,是对每个 ...
- C# interface 的特性 无法被implement class继承
最近做interface添加特性后,implement class 无法继承. 微软要求class是实现Interface而不是继承,所以我们必须手动添加特性,而不能自动继承. 对于abstract ...