B. Heaters ( Codeforces Round #515 (Div. 3) )
题解:对于每个点 i 来说,从 j = i + r - 1 开始往前找,如果找到一个 a [ j ] 是 1 ,那么就把它选上,但是我们需要判断交界处,也就是如果前面选的那个可以让这个点变温暖,就不用再选多余的了。这样就记录一下前一个 last ,要满足 j > last。找到之后,就更新 i 的值,在 i + k 之间的都可以由选的这个点来温暖。
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int a[2005];
int main()
{
int n,r;
while(scanf("%d%d",&n,&r) != EOF)
{
memset(a,0,sizeof(a));
for(int i = 1; i <= n; i ++)
{
scanf("%d",&a[i]);
}
int num = 0;
int last = 0,j,k;
for(int i = 1; i <= n;)
{
j = i + r - 1;
k = 0;
while(j > last)
{
if(a[j])
{
k = j;
break;
}
else j --;
}
if(k == 0) {printf("-1\n");return 0;}
else {
last = k;
num ++;
i = r + k;
}
}
printf("%d\n",num);
}
return 0;
}
B. Heaters ( Codeforces Round #515 (Div. 3) )的更多相关文章
- 【CodeForces】841D. Leha and another game about graph(Codeforces Round #429 (Div. 2))
[题意]给定n个点和m条无向边(有重边无自环),每个点有权值di=-1,0,1,要求仅保留一些边使得所有点i满足:di=-1或degree%2=di,输出任意方案. [算法]数学+搜索 [题解] 最关 ...
- B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))
B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
- 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))
[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...
- D. Zero Quantity Maximization ( Codeforces Round #544 (Div. 3) )
题目链接 参考题解 题意: 给你 整形数组a 和 整形数组b ,要你c[i] = d * a[i] + b[i], 求 在c[i]=0的时候 相同的d的数量 最多能有几个. 思路: 1. 首先打开 ...
- Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...
- CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))
题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发 问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候 如果对于一条边 ...
- 贪心+构造( Codeforces Round #344 (Div. 2))
题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列: 2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...
- A. Kyoya and Photobooks(Codeforces Round #309 (Div. 2))
A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ...
随机推荐
- 手写ORM入门篇(一)
对象关系映射(英语:(Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换 . ...
- json_rpc_2 implementation
https://stackoverflow.com/questions/52670255/flutter-json-rpc-2-implementation import 'dart:convert' ...
- 常用模块 - configparse模块
一.简介 configparser模块在Python中是用来读取配置文件的,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节点(section),每个节可以有多个参数(键=值 ...
- 记录axios在IOS上不能发送的问题
最近 遇到 了axios在IOS上无法发送的问题,测试 了两个 苹果 机,IOS10上不能发送,IOS12可以,百度了下,找到了解决方法.记录下吧 首先引入qs,这个安装axios也已经有了吧:然后在 ...
- iOS应用安全开发,你不知道的那些事
来源:http://www.csdn.net/article/2014-04-30/2819573-The-Secret-Of-App-Dev-Security 摘要:iOS应用由于其直接运行在手机上 ...
- Centos7搭建Harbor私有仓库(一)
1 说明 前文Centos7搭建DockerRegistry介绍了DockerRegistry的搭建,但它没有UI页面,因此选择Harbor 以下基于镜像CentOS-7-x86_64-Minimal ...
- Flask入门很轻松 (一)
转载请在文章开头附上原文链接地址:https://www.cnblogs.com/Sunzz/p/10956837.html Flask诞生于2010年,是Armin ronacher(人名)用 Py ...
- Python 多线程爬取站酷(zcool.com.cn)图片
极速爬取下载站酷(https://www.zcool.com.cn/)设计师/用户上传的全部照片/插画等图片. 项目地址:https://github.com/lonsty/scraper 特点: 极 ...
- MSF MS12-020RDP漏洞攻击
Metasploit利用远程桌面协议RDP拒绝访问漏洞(MS12-020) 漏洞描述:BUGTRAQ ID: 52354 CVE ID: CVE-2012-0152 远程桌面协议(RDP, Remot ...
- Codeforces G. Ciel the Commander
题目描述: Ciel the Commander time limit per test 1 second memory limit per test 256 megabytes input stan ...