LOJ P10012 Best Cow Fences 题解
每日一题 day48 打卡
Analysis
二分答案,判断序列的平均值是否大于等于mid
具体怎么实现呢?
将序列减去mid,再用前缀和来维护平均值就好了
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #define int long long
- #define maxn 100000+10
- #define INF 2147483647
- #define rep(i,s,e) for(register int i=s;i<=e;++i)
- #define dwn(i,s,e) for(register int i=s;i>=e;--i)
- using namespace std;
- inline int read()
- {
- int x=,f=;
- char c=getchar();
- while(c<''||c>'') {if(c=='-') f=-; c=getchar();}
- while(c>=''&&c<='') {x=x*+c-''; c=getchar();}
- return f*x;
- }
- inline void write(int x)
- {
- if(x<) {putchar('-'); x=-x;}
- if(x>) write(x/);
- putchar(x%+'');
- }
- int n,L,l,r,ans;
- int a[maxn],sum[maxn],b[maxn];
- inline bool check(int x)
- {
- rep(i,,n) b[i]=a[i];
- rep(i,,n) b[i]-=x;
- rep(i,,n) sum[i]=sum[i-]+b[i];
- int min_val=INF;
- rep(i,L,n)
- {
- min_val=min(min_val,sum[i-L]);
- if(sum[i]-min_val>=) return true;
- }
- return false;
- }
- signed main()
- {
- n=read();L=read();
- rep(i,,n)
- {
- a[i]=read();
- a[i]*=;
- }
- l=,r=;
- while(l<r)
- {
- int mid=(l+r+)/;
- if(check(mid)==true)
- {
- ans=mid;
- l=mid;
- }
- else r=mid-;
- }
- if(ans%==) write(ans+);
- else write(ans);
- return ;
- }
请各位大佬斧正(反正我不认识斧正是什么意思)
LOJ P10012 Best Cow Fences 题解的更多相关文章
- loj#10012\poj2018 Best Cow Fences(二分)
题目 #10012 「一本通 1.2 例 2」Best Cow Fences 解析 有序列\(\{a_i\}\),设\([l,r]\)上的平均值为\(\bar{x}\),有\(\sum_{i=l}^r ...
- POJ2018 Best Cow Fences —— 斜率优化DP
题目链接:https://vjudge.net/problem/POJ-2018 Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K T ...
- POJ 2018 Best Cow Fences(二分+最大连续子段和)
Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14601 Accepted: 4720 Desc ...
- POJ-2018 Best Cow Fences(二分加DP)
Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10174 Accepted: 3294 Desc ...
- 一本通 1434:【例题2】Best Cow Fences
Best Cow Fences 二分答案 + 前缀和 个人认为题意没有表述清楚,本题要求的是满足题意的连续子序列(难度大大降低了有木有). 本题的精度也是非常令人陶醉,请您自行体会吧! #includ ...
- 1434:【例题2】Best Cow Fences
1434:[例题2]Best Cow Fences 时间限制: 1000 ms 内存限制: 65536 KB提交数: 263 通过数: 146 [题目描述] 给定一个长度为n的 ...
- Poj 2018 Best Cow Fences(分数规划+DP&&斜率优化)
Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Description Farmer John's farm consists of a ...
- POJ 2018 Best Cow Fences(二分最大区间平均数)题解
题意:给出长度>=f的最大连续区间平均数 思路:二分这个平均数,然后O(n)判断是否可行,再调整l,r.判断方法是,先求出每个数对这个平均数的贡献,再求出长度>=f的最大贡献的区间,如果这 ...
- 题解0002:Best Cow Fences
题目描述:给定一个长度为n的正整数序列A.求一个平均数最大的,长度不小于L的子序列,输出这个平均数*1000. 题目链接:http://ybt.ssoier.cn:8088/problem_show. ...
随机推荐
- Java的含义
Java是一种广泛使用的计算机编程语言,拥有跨平台.面向对象.泛型编程的特性,广泛应用于企业级Web应用开发和移动应用开发. Java语言它不是软件,这里给各位初学者们详细解释一下.简单来说计算机语言 ...
- 树莓派搭建python环境服务器
树莓派搭建python环境服务器 服务器结构大致为:django+uwsgi+nginx+python+sqlite 配置python环境 系统本身自带了python2.7和python3.5.在这里 ...
- golang 之 context包
概述 context是Go中广泛使用的程序包,由Google官方开发,在1.7版本引入.它用来简化在多个go routine传递上下文数据.(手动/超时)中止routine树等操作,比如,官方 ...
- 【题解】Luogu P5338 [TJOI2019]甲苯先生的滚榜
原题传送门 这题明显可以平衡树直接大力整,所以我要说一下线段树+树状数组的做法 实际线段树+树状数组的做法也很暴力 我们先用树状数组维护每个ac数量有多少个队伍.这样就能快速求出有多少队伍ac数比现在 ...
- 切换GCC编译器版本
当前版本信息 root@ubuntu:runninglinuxkernel_4.0# aarch64-linux-gnu-gcc -v Using built-in specs. COLLECT_GC ...
- CSS控制DIV水平垂直居中
<div style="position:absolute; width: 600px; height: 200px; left: 50%; top: 50%; margin-left ...
- Apple SIP简介及在Clover中如何控制
Apple SIP简介及在Clover中如何控制 来源 http://www.yekki.me/apple-sip-overview-and-how-to-disable-it-in-clover/ ...
- ssm(spring+springmvc+mybatis)整合之环境配置
1-1.导包 导入SpringMVC.Spring.MyBatis.mybatis-spring.mysql.druid.json.上传和下载.验证的包 1-2.创建并配置web.xml文件 配置sp ...
- 【openshift】OC命令部署Openshift
OC命令部署Openshift # install openshift wget -c https://github.com/openshift/origin/releases/download/v3 ...
- 【夯实基础】- Integer.valueof()和Integer.parseInt()的区别
今天在看公司代码的时候,看到有人在将 String 转为 int 时,用到了Integer.parseInt(String s)方法,我一直用的是Integer.valueOf(String s)方法 ...