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 ...
随机推荐
- Tell Me About Yourself Example 1
Tell Me About Yourself Employers ask this question because they want to know you have the relevant e ...
- wordpress使用rsync加openvpn进行同步和备份
目录 wordpress使用rsync加openvpn进行同步和备份 环境 普通同步策略的弊端 改良的同步方案 从头细说起 备份数据 打包wordpress项目和备份 服务端安装rsync 服务端配置 ...
- Hbase-2.0.0_02_常用操作
主要是常用的hbase shell命令,包括表的创建与删除,表数据的增删查[hbase没有修改]:以及hbase的导出与导入. 参考教程:HBase教程 参考博客:hbase shell基础和常用命令 ...
- 五、git创建及合并分支
1. 创建并切换到dev分支 git checkout -b dev // git checkout命令加上-b参数表示创建并切换,相当于以下两条命令 git branch dev git check ...
- vue框架简介
MVVM框架概述 什么是vue 是一套构建用户界面的渐进式(用到哪一块就用哪一块,不需要全部用上)前端框架,Vue 的核心库只关注视图层 vue的兼容性 Vue.js 不支持 IE8 及其以下版本,因 ...
- swift函数的调用约定
The convention of the function, indicated by the attribute. This is similar to the language-level @c ...
- day15 Python函数递归,轻易不要用递归,容易搞出来内存溢出
古之欲明明德于天下者,先治其国:欲治其国者,先齐其家:欲齐其家者,先修其身:欲修其身者,先正其心:欲正其心者,先诚其意:欲诚其意者,先致其知,致知在格物.物格而后知至,知至而后意诚,意诚而后心正,心正 ...
- loback学习
博客链接 http://aub.iteye.com/blog/1101222
- 分布式爬虫之elasticsearch基础6(bluk)
上篇文章介绍了在es里面批量读取数据的方法mget,本篇我们来看下关于批量写入的方法bulk. bulk api可以在单个请求中一次执行多个索引或者删除操作,使用这种方式可以极大的提升索引性能. bu ...
- mysql 数据表 增删改查
用户操作: mysql -u root -p 登录root用户: SHOW DATABASES; 显示所有的数据库名称: USE linuxcast; 切入linuxcast数据库: CREATE T ...