题目链接

题意分析

首先我们可以得出计算公式

\[s_i=\prod_{k=1}^i(1-p_k)
\]

\[f_i=\sum_{k=1}^i\frac{p_k}{1-p_k}
\]

那么

\[ans(i,j)=\frac{s_r}{s_{l-1}}{f_r-f_{l-1}}
\]

强行枚举 \(O(n^2)\)

我们冷机观察一波发现 可以使用尺取法

然后优化成了\(O(n)\)

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<vector>
#include<ctime>
#define ll long long
#define inf 0x7fffffff
#define N 500008
#define IL inline
#define M 1008611
#define D long double
#define R register
using namespace std;
template<typename T>IL void read(T &_)
{
T __=0,___=1;char ____=getchar();
while(!isdigit(____)) {if(____=='-') ___=0;____=getchar();}
while(isdigit(____)) {__=(__<<1)+(__<<3)+____-'0';____=getchar();}
_=___ ? __:-__;
}
/*-------------OI使我快乐-------------*/
int n;
D num[M],cdy=1.0,wzy,ans;
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
read(n);
for(R int i=1,x;i<=n;++i)
{
read(x);
num[i]=((D)x/1000000.0);
ans=max(ans,num[i]);
}
for(R int i=1,tail=1;i<=n;++i)
{
while(tail<=n&&cdy*wzy<cdy*(1.0-num[tail])*(wzy+num[tail]/(1.0-num[tail])))
{
cdy*=(1.0-num[tail]);
wzy+=num[tail]/(1.0-num[tail]);
++tail;
}
ans=max(ans,cdy*wzy);
cdy/=(1.0-num[i]);wzy-=num[i]/(1.0-num[i]);
}
printf("%d\n",(int)(ans*1000000));
// fclose(stdin);
// fclose(stdout);
return 0;
}

HEOI 2019 RP++

P5242 [USACO19FEB]Cow Dating的更多相关文章

  1. 洛谷 P5242 [USACO19FEB]Cow Dating P

    这道题很有意思. 不难发现,对于一个区间 \([l, r]\),恰好只有一个奶牛接受邀请的概率为 \[\prod_{i=l}^r(1-p_i) \cdot \sum_{i=l}^r \frac {p_ ...

  2. [USACO19FEB]Cow Dating

    Luogu5242 通过观察数据,我们可以发现,右端点的取值是单调递增的.于是,我们可以极限一波,用一个双指针法,类似于队列. 右端点的取值满足以下公式: (1-p1)(1-p2)..(1-pn) * ...

  3. [USACO19FEB]Cow Dating——找规律

    原题戳这里 题解 显然原题等价于让我们求这个式子\(\prod\limits_{i=l}^{r}(1-p_i)\sum\limits_{i=l}^{r}\frac{p_i}{1-p_i}\)的最大值是 ...

  4. 题解 P6098 【[USACO19FEB]Cow Land G】

    震惊,蒟蒻学树剖第二天就打题解 所以说,理解之后树剖这种东西其实难度真心不大.至少这种模板题都可以秒切的 这里推荐一个博客: 树剖详解 蒟蒻就是在这个博客上学到的 如果想看我自己写的总结,请点 我的博 ...

  5. 树链剖分详解&题解 P6098 【[USACO19FEB]Cow Land G】

    看到各位大佬们已经把其他的东西讲的很明白了,我这个 juruo 就讲一讲最基本的树链剖分吧. 0.树剖是什么?能吃吗? 不能吃 树剖是树链剖分的简称,我们一般说的树剖其实指重链剖分.当然,还有一种长链 ...

  6. P5541 [USACO19FEB]Sleepy Cow Herding

    ri,被黄题虐. 思路:贪心?? 提交:2次 错因:没有特判 题解: 先排序. 最小代价:固定区间长度为\(n\),我们扫一遍数组看区间最多包含几个数,设为 \(mx\) ,答案就是\(n-mx+1\ ...

  7. POJ 3278 Catch That Cow(bfs)

    传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25 ...

  8. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

  9. HDU Cow Sorting (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1  ...

随机推荐

  1. 用jquery实现html5的placeholder功能

    html5的placeholder功能在表单中经常用到,它主要用来提示用户输入信息,当用户点击该输入框之后,提示文字会自动消失. 我们用jquery实现类似的功能: 当输入框获得焦点时,清空输入框中的 ...

  2. shell如何传递变量到另一个脚本文件中

    http://www.jbxue.com/article/shell/20707.html本文介绍了shell脚本传递变量到另一个脚本文件中的方法,在脚本中调用另一脚本,即创建了一个子进程,感兴趣的朋 ...

  3. How to setup Laravel Homestead in Windows

    How to setup Laravel Homestead in Windows by JBorbón  17. March 2017   PHP   8 Developing with PHP u ...

  4. numpy中tile()函数

    函数形式: tile(A,rep) 功能:重复A的各个维度 参数类型: - A: Array类的都可以,即A是一个ndarry数组- rep:A沿着各个维度重复的次数,表示变成的矩阵的形状,例如rep ...

  5. 视频转换工具ffmpeg

    安装ffmpeg ffmpeg官网下载地址点击此处. 如果使用mac也可用homebrew下载安装:brew install ffmpeg 使用ffmpeg 命令如下:ffmpeg -i input. ...

  6. 测试用Word2007发布博客文章

    目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...

  7. Linux 基础教程 28-nc命令

    nc     nc命名netcat,直译为网络猫.在CentOS 7查看帮助的解释如下所示: ncat - Concatenate and redirect sockets 翻译过来就是可以连接和重定 ...

  8. scala中Nil用法

    http://www.runoob.com/scala/scala-lists.html 即Nil是空List 双冒号是追加进入 package com.yjsj.spark object scala ...

  9. [label][phalcon] How to install Phalcon extension for Zend Server 6.3.0 for windows 7 64bit

    At first , you should download Phalcon DLL file. You can download from this link under. http://stati ...

  10. centos 7.6 开机报错信息(一):welcome to emergency mode!

    welcome to emergency mode!after logging in ,type "journalctl -xb" to view system logs,&quo ...