思路:
首先要明确,在一段左端点为 ,右端点为 的区间内仅被一头奶牛选中的概率是 。
变式得到:。
设置两个决策点 和 。假设 优于 且 。设 ,。
于是可得不等式:。
变式得 。
。
。
。
用这个斜率式求上凸壳,就行了。
AC 代码:
#include<bits/stdc++.h>
#define double long double
using namespace std;
const int N = 1e6 + 10;
int n, hd = 1, tl, j;
double a[N], s[N], m[N], q[N], ans;
double x(int i) {
return 1.0 / m[i];
}
double y(int i) {
return s[i] / m[i];
}
double k(int i, int j) {
return (y(j) - y(i)) * 1.0 / (x(j) - x(i));
}
int main() {
cin >> n;
m[0] = 1;
for (int i = 1; i <= n; i++) {
double x;
cin >> x;
a[i] = x / 1000000.0;
s[i] = s[i - 1] + a[i] / (1.0 - a[i]);
m[i] = m[i - 1] * (1.0 - a[i]);
}
q[++tl] = 0;
for (int i = 1; i <= n; i++) {
while (hd < tl && k(q[hd], q[hd + 1]) < s[i]) {
hd++;
}
j = q[hd];
ans = max(ans, (m[i] / m[j]) * (s[i] - s[j]) * 1.0);
while (hd < tl && k(q[tl - 1], q[tl]) > k(q[tl - 1], i)) {
tl--;
}
q[++tl] = i;
}
cout << (int)(ans * 1000000);
return 0;
}
/*
*
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┗━┓ ┏━┛ + +
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the llama protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
//thanks cindy