【POJ 2018】 Best Cow Fences
【题目链接】
http://poj.org/problem?id=2018
【算法】
二分平均值
检验时将每个数减去二分的值,求长度至少为L的子序列和的最大值,判断是否大于0
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100010
const double eps = 1e-; int n,f,i;
double a[MAXN],b[MAXN],s[MAXN];
double l,r,mid,ans; inline bool check(double x)
{
int i;
double mn = 1e6,ret = -1e6;
for (i = ; i <= n; i++) b[i] = a[i] - x;
for (i = ; i <= n; i++) s[i] = s[i-] + b[i];
for (i = f; i <= n; i++)
{
mn = min(mn,s[i-f]);
ret = max(ret,s[i]-mn);
}
return ret >= ;
} int main() { scanf("%d%d",&n,&f);
for (i = ; i <= n; i++) scanf("%lf",&a[i]);
l = -1e6; r = 1e6;
while (r - l > eps)
{
mid = (l + r) / ;
if (check(mid)) l = mid;
else r = mid;
}
printf("%d\n",int(r*)); return ; }
【POJ 2018】 Best Cow Fences的更多相关文章
- 1434:【例题2】Best Cow Fences
1434:[例题2]Best Cow Fences 时间限制: 1000 ms 内存限制: 65536 KB提交数: 263 通过数: 146 [题目描述] 给定一个长度为n的 ...
- 【POJ 3263】 Tallest Cow
[题目链接] http://poj.org/problem?id=3263 [算法] 若A和B两头牛可以互相看见,那么说明中间的牛的高度都至少比它们少1,因此,我们可以引入一个差分数组c 对于每组关系 ...
- 一本通 1434:【例题2】Best Cow Fences
Best Cow Fences 二分答案 + 前缀和 个人认为题意没有表述清楚,本题要求的是满足题意的连续子序列(难度大大降低了有木有). 本题的精度也是非常令人陶醉,请您自行体会吧! #includ ...
- 【POJ 3623】 Best Cow Line, Gold (后缀数组)
[题意] [分析] 后缀数组水题,嗯,不认真看输出像我一样就会被坑.. #include<cstdio> #include<cstdlib> #include<cstri ...
- 【POJ - 3268 】Silver Cow Party (最短路 Dijkstra算法)
Silver Cow Party Descriptions 给出n个点和m条边,接着是m条边,代表从牛a到牛b需要花费c时间,现在所有牛要到牛x那里去参加聚会,并且所有牛参加聚会后还要回来,给你牛x, ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
随机推荐
- Java基础(四)--接口和抽象类
接口和抽象类能够体现OOP的抽象,而接口和抽象类也是日常开发中经常用到的 抽象方法: 抽象方法就是被abstract修饰的方法,只有声明,没有实现,也就是没有方法体 public abstract v ...
- Redis系列(三)--消息队列、排行榜等
Redis命令执行生命周期: 发送命令--->排队(单线程)--->执行命令--->返回结果 慢查询: 只是针对命令执行阶段 慢查询日志通过一个固定长度的FIFO queue,这个q ...
- Java必知必会的20种常用类库和API
转载:https://blog.csdn.net/u011001084/article/details/79216958 个人感觉工具类对日常开发是很重要的,所以推荐一下这篇文章,虽然有的类库过时了 ...
- 00HyperText Markup Language
HyperText Markup Language HTML超文本标记语言是一种用于创建网页的标准标记语言用于显示网页内容,HTML运行在浏览器上,由浏览器来解析,您可以使用 HTML 来建立自己的 ...
- 【转载】linux下的zookeeper启动
zookeeper的安装目录:/usr/local/zookeeper-3.4.6/bin/zkServer.sh; 配置文件路径:../conf/zoo.cfg 端口 :2181: ZooKeepe ...
- 新一代 Linux 文件系统 btrfs 简介
https://www.ibm.com/developerworks/cn/linux/l-cn-btrfs/ Btrfs 简介 文件系统似乎是内核中比较稳定的部分,多年来,人们一直使用 ext2/3 ...
- 了解固态硬盘SSD,竟然如此简单!小白也能懂!
https://www.youtube.com/watch?v=alb6-zp52mA
- acm相关(纯转载)
我觉得很好的文章,之所以放随笔是为了让大家看到这些优秀的博文 acm如何起步 acm重点题型 动态规划题目总结 背包九讲阅读网站
- 为什么map对象不能使用stl中的sort函数
STL所提供的各式各样算法中,sort()是最复杂最庞大的一个.这个算法接受两个RandomAccestlerators(随机存取迭代器),然后将区间内的所有元素以渐增方式由小到大重新排列.第二个版本 ...
- Xshell(smarTTY)连接Linux虚拟机失败(未开放22端口)解决办法
1.关闭防火墙: 命令:sudo ufw disable 2.安装openssh-server以及openssh-client: 命令:sudo apt-get install openssh-ser ...