B. Heaters Div3
链接
[http://codeforces.com/contest/1066/problem/B]
分析
具体看代码,贪就完事了
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,r,k,i,pos;
int a[1010];
//freopen("in.txt","r",stdin);
while(cin>>n>>r){
memset(a,0,sizeof(a));
for(i=1;i<=n;i++)
{
cin>>k;
if(k==1)//可以往两边发散的点
{
for(pos=max(1,i-r+1); pos<=min(n,r+i-1); pos++)//贪心模拟
{
a[pos]=max(a[pos],i);//所能覆盖的区域,每个位置尽可能往后贪即可
}
}
}
int ans=0;
i=1;
while(i<=n){
if(a[i]==0) {
ans=-1;
break;
}
ans++;
i=a[i]+r;//因为i这个位置最右边的覆盖点,一定可以把自己两边的区域覆盖
}
cout<<ans<<endl;
}
return 0;
}
B. Heaters Div3的更多相关文章
- [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 ...
- Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)
Problem Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...
- codeforces-1144 (div3)
赛后经验:div3过于简单,以后不做了 A.存在以下情况即为NO 1.存在相同字母 2.最大字母-最小字母 != 字符串长度 #include <map> #include <set ...
- [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 ...
随机推荐
- 使用Python语言理解递归
递归 一个函数在执行过程中一次或多次调用其本身便是递归,就像是俄罗斯套娃一样,一个娃娃里包含另一个娃娃. 递归其实是程序设计语言学习过程中很快就会接触到的东西,但有关递归的理解可能还会有一些遗漏,下面 ...
- Eclipse配置和使用Maven
一.ecplise配置Maven 1.下载eclipse的Maven插件.(有些eclipse版本中已经集成了此Maven插件,可以不用下载). 需要下载m2eclipse插件. 2.安装m2ecli ...
- 解决内存不能为read错误
解决方法 1. 命令解决方法:开始菜单,运行,输入cmd,回车,在命令提示符下输入(复制即可) :for %1 in (%windir%\system32\*.ocx) do regsv ...
- MySQL内连接(INNER JOIN)
MySQL INNER JOIN子句介绍 MySQL INNER JOIN子句将一个表中的行与其他表中的行进行匹配,并允许从两个表中查询包含列的行记录. INNER JOIN子句是SELECT语句的可 ...
- JSON语法规则
JSON 语法规则 JSON 语法是 JavaScript 对象表示法语法的子集. 数据在名称/值对中 数据由逗号分隔 花括号保存对象 方括号保存数组 JSON 名称/值对 JSON 数据的书写格式是 ...
- Pandas 库中excel的读写方法介绍
首选:https://blog.csdn.net/u014597198/article/details/83104653 其次:https://blog.csdn.net/qq_34377830/ar ...
- VMware NAT 设置原理
1.网络地址转换(NAT):默认使用VMnet8 (强烈推荐) 这种访问模式指的是虚拟机不占用主机所在局域网的ip,通过使用主机的NAT功能访问局域网和互联网,意味着虚拟机可以访问局域网中的其他电脑, ...
- Android之activity总结
http://www.cnblogs.com/lyp3314/archive/2011/11/10/2244971.html 一.什么是activity Activity 是用户接口程序,原则上它会提 ...
- luogu P4146 序列终结者
嘟嘟嘟 这是一道splay基础题. 最坑的一点是,因为有些节点可能没有左儿子或右儿子,所以必须把t[0].Max赋成-INF! 因为这个调了半天,看来回头复习复习splay是对的-- #include ...
- 理解 JavaScript 中的 for…of 循环
什么是 for…of 循环 for...of 语句创建一个循环来迭代可迭代的对象.在 ES6 中引入的 for...of 循环,以替代 for...in 和 forEach() ,并支持新的迭代协议. ...