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]结束。
如果从ii出发,每次向左或向右走,走到L或R停止,那么
最终停在R的概率为(i – L) / (R – L)。
最终停在L的概率为(R – i) / (R – L)。
换句话说,设pi是停在R的概率,显然有pL = 0, pR = 1
中间的pi是一个等差数列。
所以说,从i出发,每次向左或向右走,走到L或R停止,这个策略的收益是(a[L]*(R–i)+a[R]*(i–L))/(R–L)
换句话说,如果点(i, ai)在从(L, a[L])到(R, a[R])的下面,那么他就可以删去了,剩下的点恰好是一个凸包。
#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; }
© 2024. All Rights Reserved. 沪ICP备2023009024号-1