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 ...
 
随机推荐
- January 26th, 2018 Week 04th Friday
			
A great forest is set on fire by a small spark. 最小的火能点着最大的树林. It is just a spark, but it is enough t ...
 - JS学习小结(上)
			
学而时习之,不亦说乎,开启JS学习新乐章~ JS是干啥的?网页特效,它主要是实现控制结构和样式,是一种行为,有多重要,不言而喻吧,页面炫酷的资本. 1. JS输出: alert("hello ...
 - 关于前缀和,A - Hamming Distance Sum
			
前缀和思想 Genos needs your help. He was asked to solve the following programming problem by Saitama: The ...
 - [NOI2005]瑰丽华尔兹
			
嘟嘟嘟 这题大家应该都做过,就是暴力dp+单调队列优化. dp方程其实很好想,最初是这样的:dp[t][i][j]表示时刻\(t\)后,走到\((i, j)\)格子的最远路程,于是就有: \[dp[t ...
 - LOOPS HDU - 3853 (概率dp):(希望通过该文章梳理自己的式子推导)
			
题意:就是让你从(1,1)走到(r, c)而且每走一格要花2的能量,有三种走法:1,停住.2,向下走一格.3,向右走一格.问在一个网格中所花的期望值. 首先:先把推导动态规划的基本步骤给出来. · 1 ...
 - 解决普通用户登录ulimit 报错问题
			
[root@master1 ~]# su - fengjian-bash: ulimit: open files: cannot modify limit: Operation not permitt ...
 - go标准库的学习-net/rpc
			
参考:https://studygolang.com/pkgdoc 导入方法: import "net/rpc" RPC(Remote Procedure Call Protoco ...
 - call()、delegatecall()
			
call()当使用方法是:require(msg.sender.call.value(_weiToWithdraw)());则作用是将_weiToWithdraw个以太币发送给msg.sender地址 ...
 - python3 练习题(购物车)
			
'''购物车程序需求:1.启动程序后,让用户输入工资,然后打印商品列表2.允许用户根据商品编号购买商品3.用户选择商品后,检查余额是否够,够就直接扣款,不够就提醒4.用户可一直购买商品,也可随时退出, ...
 - lombok的使用和原理
			
一.项目背景 在写Java程序的时候经常会遇到如下情形: 新建了一个Class类,然后在其中设置了几个字段,最后还需要花费很多时间来建立getter和setter方法 lombok项目的产生就是为了省 ...