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 ...
随机推荐
- VMware安装CentOS6
1. 搭建虚拟化环境常见故障讲解 2. 安装CentOS Linux系统 ……………… PS:运维老鸟教你安装centos6.5如何选择安装包 3. 远程连接LInux ip配置 注意:不用做任何修改 ...
- Linux 小知识翻译 - 「环境变量」
这次,谈谈关于「环境变量」的话题. 所谓变量,就是在程序中设置的,相当于在内存中准备的「一个用来存放数据的小箱子」. 即,程序通过变量来保存值,通过变量保存的内容来进行各式各样的计算处理. 「环境变量 ...
- JavaScript中数组的增删改查以及应用方式
数组的增加方法 1.push()方法向数组中末尾添加一个元素,原数组改变 var arr=[1,2,3,4]; var arr1=arr.push(6); console.log(arr);//打印出 ...
- Source Insight4 破解安装
首先确保你在官网下载了原版4.0并安装好了. 1,下载如下的sourceinsight4.exe文件,替换安装文件夹下的sourceinsight4.exe. 链接:http://pan.baidu. ...
- IE8以下兼容
<!--[if lt IE 9]><script type="text/javascript">alert('IE版本太低,请升级后使用');</sc ...
- 2017-2018-2 20155314《网络对抗技术》Exp6 信息搜集与漏洞扫描
2017-2018-2 20155314<网络对抗技术>Exp6 信息搜集与漏洞扫描 目录 实验目标 实验内容 实验环境 基础问题回答 预备知识 实验步骤 1 信息搜集 1.1 外围信息搜 ...
- JavaWeb界面在线配置代码生成器
关于直接main方法运行生成代码可参考我的这篇文章:MP实战系列(六)之代码生成器讲解 在线配置主要参考jeesite和jeecg,gun等开源项目,但是与它们相比又有很多不同? 与jeesite相比 ...
- all与any的用法
all函数:检测矩阵中是否全为非零元素 any函数:检测矩阵中是否有非零元素,如果有,则返回1,否则,返回0.用法和all一样 语法: B = all(A) B = all(A, dim) 复制代码 ...
- MATLAB 图形着色
1.matlab中的颜色查找表函数: (1)autumn:从红色向橘黄色.黄色平稳过渡: (2)bone:为含有较高的蓝色组分的gray颜色查找表: (3)colorcube:包含RGB颜色空间中尽可 ...
- Python基础(5)——函数
函数 定义 #函数定义 def calc(x,y): res = x**y return res #返回函数执行结果 calc() #调用函数 关键参数 正常情况下,给函数传参数要按顺序,不想按顺序就 ...