Codeforces B Let's Play Osu!

题目大意

  现在有一个长度为n的只有ox组成的字符串。第i个位置上有pi的概率出现o,(1-pi)的概率出现x,如果有一段长度为L的全是o的部分,贡献就是L^2。求最后贡献的期望。

题解

  这题有点思博啊……首先我们对于一个确定的串,从前往后扫,设当前o的长度为L,如果下一个是o的话,那么贡献就会增加(L+1)^2-L^2=2L+1.这样的话从前往后扫,我们维护两个值,一个是当前期望的o的长度now,一个是期望贡献ans,这样ans+=(2*now+1)*pi,now=(now+1)*pi

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstdlib>
 5 #include<cstring>
 6 using namespace std;
 7 int n;
 8 double p,now,ans;
 9 int main()
10 {
11     ans=0.0;now=0.0;
12     scanf("%d",&n);
13     for(int i=1;i<=n;i++)
14     {
15         cin>>p;
16         ans+=(2*now+1)*p;now=(now+1)*p;
17     }
18     printf("%.10f",ans);
19     return 0;
20 }

Codeforces B Let's Play Osu!

时间: 2024-08-12 13:17:52

Codeforces B Let's Play Osu!的相关文章

Codeforces 235B. Let&#39;s Play Osu!

235B - Let's Play Osu! Let us take a deep look in how this score is calculated. for a n long 'O' block, they contribute n2 to answer. Let us reformat this problem a bit and consider the following problem. For each two 'O' pair which is no 'X' between

codeforces 235B Let&#39;s Play Osu! 概率dp

题意:给定n表示有n个格子,下面每个格子为O的概率是多少.对于一段连续 x 个O的价值就是 x^2 ;求获得的价值的期望是多少. 思路:n^2=n×(n-1)+n,设ai为第i段连续O的长度,∑ai^2 = ∑[ ai+ ai*(ai-1) ] = ∑ ai*(ai-1) + ∑ai = ∑ C(ai, 2)*2 + ∑ai,那么问题可以转 化为求长度大于1的连续段数*2+O的个数的总期望. ∑ai我们可以理解为O的总个数,所以它的期望为∑pi: C(ai, 2)*2我们可以认 为是连续ai个O

Codeforces 235B Let&#39;s Play Osu! (概率dp求期望+公式变形)

B. Let's Play Osu! time limit per test:2 seconds memory limit per test:256 megabytes You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us deno

Codeforces 235B Let&#39;s Play Osu! 概率dp(水

题目链接:点击打开链接 给定n表示有n个格子 下面每个格子为O的概率是多少. 对于一段连续 x 个O的价值就是 x*x ; 问: 获得的价值的期望是多少. 思路: 把公式拆一下.. #include <cstdio> const int N = 100005; double dp[N][2], p[N]; int main(){ int n; scanf("%d", &n); for(int i = 1; i <= n; i ++) { scanf("

codeforces 235 B lets play osu!

cf235B 一道有意思的题.(据说是美少女(伪)计算机科学家出的,hh) 根据题目要求,就是求ni^2的和. 而n^2=n*(n-1)+n; n*(n-1)=C(n,2)*2: 所以∑ai^2=∑ai+2*∑C(n,2) 化为求连续长度大于2的序列个数:这样好像还是不太好直接做 设dp[i]=以i结尾的期望长度: dp[0]=dp[1]=0,dp[2]=p1p2,dp[3]=p1p2p3+p2p3=(dp[2]+p[2])*p3  ... 得dp[i]=p[i]*(dp[i-1]+p[i-1]

[Codeforces Round #146 (Div. 1) B]Let&#39;s Play Osu!(期望Dp)

Description You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be

bzoj4318: OSU!&amp;&amp;CF235BLet&#39;s Play Osu!

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4318 4318: OSU! Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 374  Solved: 294[Submit][Status][Discuss] Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: 一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b