Codeforces Round #351 (VK Cup 2016 Round 3, Div. 1 Edition) C E （斜率优化. 概率）

Levels and Regions

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <bitset>
#include <queue>
using namespace std;

#define LL long long
#define ULL unsigned long long
#define eps 1e-9
#define N (200000 + 10)
#define M (400000 + 10)
#define pii pair<int,int>
#define MP make_pair
#define inf 0x3f3f3f3f
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define mod 1000000007

int a[N];
double s[N];
double t[N], g[N];
double dp[N][60];

struct node {
double x, y;
int id;
node() {}
node(double x, double y, int id) : x(x), y (y) ,id(id){};
}que[N];

bool check(node a, node b, node c) {
return (b.y - a.y) * (c.x - a.x) >= (c.y - a.y) * (b.x - a.x);
}

void insert(double x, double y, int id) {
node tmp = node(x, y, id);
while(cnt > 1 && check(que[cnt-2], que[cnt-1], tmp)) --cnt;
que[cnt++] = tmp;
}

bool judge(node a, node b, double x) {
return b.y - a.y < x * (b.x - a.x);
}

int query(double x) {
}

void debug(int l, int r) {
double ans = g[r] - g[l-1];
for(int i = l; i <= r; ++i)
ans += t[r] * a[i];
printf("l %d r %d ans %.10lf\n", l, r,ans);
}
int main() {
//freopen("in.in", "r", stdin);
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]), s[i] = s[i-1] + a[i];
t[i] = 1.0/a[i] + t[i-1];
g[i] = a[i] * t[i-1] + g[i-1];
}
for(int i = 1; i <= n; ++i)
dp[i][0] = 1e30;
for(int j = 1; j <= k; ++j) {
insert(0, 0, 0);
for(int i = j-1; i < j; ++i)
insert(s[i], dp[i][j-1]+g[i], i);
for(int i = j; i <= n; ++i) {
int k = query(t[i]);
dp[i][j] = dp[k][j-1] + s[i] * t[i] - g[i] - s[k] * t[i] + g[k];
insert(s[i], dp[i][j-1]+g[i], i);
}
}
printf("%.10lf\n", dp[n][k]);
}

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <bitset>
#include <queue>
using namespace std;

#define LL long long
#define ULL unsigned long long
#define eps 1e-9
#define N (500000 + 10)
#define M (400000 + 10)
#define pii pair<int,int>
#define MP make_pair
#define inf 0x3f3f3f3f
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define mod 1000000007

double ans[N][66];
int fa[N];
int tot;
const int Max = 50;
int main() {
int n;
scanf("%d", &n);
tot = 1;
ans[0][0] = 0;
for(int i = 1; i<= Max; ++i)
ans[0][i] = 1;
while(n--) {
int op, u;
scanf("%d%d", &op, &u);
--u;
if(op == 2) {
double ret = 0;
for(int i = 1; i <= Max; ++i)
ret += (1 - ans[u][i]);
printf("%.10lf\n", ret);
}
else {
fa[tot] = u;
ans[tot][0] = 0;
for(int i = 1; i <= Max; ++i) ans[tot][i] = 1;
double tmp = 0.5;
double pre = 0, last = 1;;
int v = tot;
for(int i = 1; i <= Max; ++i) {
pre = ans[u][i];
ans[u][i] /= (0.5 * last + 0.5);
ans[u][i] *= (0.5 * ans[v][i-1] + 0.5);
last = pre;
tmp *= 0.5;
if(!u) break;
v = u;
u = fa[u];
}
++tot;
}
}
}

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A B C D 模拟

2016-04-25 23:02:34

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D

2017-02-28 20:18:50

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)

2016-05-08 21:39:51

VK Cup 2018 Round 2 div2 C, D 题解 【思维题】

2018-03-26 11:51:17

Codeforces 658A B C || VK Cup 2016 - Round 1 (Div. 2 Edition) A B C题解

2016-03-29 15:44:25

Codeforces Round #423(Div.2)

2017-07-12 03:48:20

【CodeForces】CodeForces Round #464 (Div. 2) 题解

2018-02-18 11:05:43

VK Cup 2018 Round 2: D. Contact ATC（思维+树状数组）

2018-03-25 17:21:19

Codeforces Round #482 (Div. 2)

2018-05-15 12:51:24

Codeforces Round #486 (Div. 3) D

2018-06-02 01:04:23