In order to save money for a new stall in her barn, Bessie the cow has started performing in the local circus, demonstrating her remarkable sense of balance as she carefully walks back and forth on an elevated balance beam!
The amount of money Bessie earns in her performance is related to where she manages to ultimately jump off the beam. The beam has positions labeled?0,1,…,N+10,1,…,N+1?from left to right. If Bessie ever reaches?00?or?N+1N+1?she falls off one of the ends of the beam and sadly gets no payment.
If Bessie is at a given position?kk, she can do either of the following:
1. Flip a coin. If she sees tails, she goes to position?k?1k?1, and if she sees heads, she goes to position?k+1k+1?(i.e.?1212?probability of either occurrence).
2. Jump off the beam and receive payment of?f(k)f(k)?(0≤f(k)≤109)(0≤f(k)≤109).
Bessie realizes that she may not be able to guarantee any particular payment outcome, since her movement is governed by random coin flips. However, based on the location where she starts, she wants to determine what her expected payment will be if she makes an optimal sequence of decisions ("optimal" meaning that the decisions lead to the highest possible expected payment). For example, if her strategy earns her payment of?1010?with probability?1/21/2,?88?with probability?1/41/4, or?00?with probability?1/41/4, then her expected payment will be the weighted average?10(1/2)+8(1/4)+0(1/4)=710(1/2)+8(1/4)+0(1/4)=7.
The first line of input contains?NN?(2≤N≤1052≤N≤105). Each of the remaining?NN?lines contain?f(1)…f(N)f(1)…f(N).
Output?NN?lines. On line?ii, print out?105105?times the expected value of payment if Bessie starts at position?ii?and plays optimally, rounded down to the nearest integer.
2 1 3
150000 300000
Problem credits: Franklyn Wang and Spencer Compton
凸包。
如果初始在i(L≤i≤R),并且a[L]a[L]和a[R]a[R]均大于a[i]a[i]。
那么必然可以以a[L]a[L]或者a[R]a[R]結(jié)束。
如果從ii出發(fā),每次向左或向右走,走到L或R停止,那么
最終停在R的概率為(i – L) / (R – L)。
最終停在L的概率為(R – i) / (R – L)。
換句話說,設(shè)pi?是停在R的概率,顯然有pL = 0, pR = 1
中間的pi?是一個(gè)等差數(shù)列。
所以說,從i出發(fā),每次向左或向右走,走到L或R停止,這個(gè)策略的收益是(a[L]*(R–i)+a[R]*(i–L))/(R–L)
換句話說,如果點(diǎn)(i, ai)在從(L, a[L])到(R, a[R])的下面,那么他就可以刪去了,剩下的點(diǎn)恰好是一個(gè)凸包。
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int n;
double a[100020];
int s[100020], ss;
long long xm(long long x1, long long y1, long long x2, long long y2) {
return x1 * y2 - x2 * y1;
}
int main() {
freopen("balance.in", "r", stdin);
freopen("balance.out", "w", stdout);
scanf("%d", &n);
s[ss++] = 0;
for (int i = 1; i <= n + 1; i++) {
if (i <= n) {
scanf("%lf", &a[i]);
}
while (ss >= 2 && xm(s[ss - 1] - s[ss - 2], a[s[ss - 1]] - a[s[ss - 2]],
i - s[ss - 2], a[i] - a[s[ss - 2]]) > 0) {
ss--;
}
s[ss++] = i;
}
int t = 0;
for (int i = 1; i <= n; i++) {
while (i > s[t]) {
t++;
}
ull res = (ull)a[s[t]] * (i - s[t - 1]) + (ull)a[s[t - 1]] * (s[t] - i);
res *= 100000;
res /= s[t] - s[t - 1];
printf("%llun", res);
}
return 0;
}

? 2025. All Rights Reserved. 滬ICP備2023009024號(hào)-1