Codeforces 235B. Let'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 them, they add 2 to score.

For each ‘O‘,it add 1 to score.

We can see that these two problem are exact the same.

Proof:

for a n long ‘O‘ block,there is Cn2 pair
of ‘O‘ in it and n ‘O‘ in it.

2Cn2?+?n?=?n2.

So for each event(i,j) (which means s[i] and s[j] are ‘O‘, and there‘s no ‘X‘ between them).

If event(i,j) happen, it add 2 to the score.

So we only sum up the probability of all events and multiply them by 2.

Then our task become how to calculate the sum of all event(i,j).

We can see event(i,j) is simpliy .

Then we denote dp(j) as sum of all event(i,j) and i<j.

so dp(0)=0 and dp(j)=(dp(j-1)+pj?-?1)*pj

B. Let‘s Play Osu!

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 encoded as a sequence of n characters "O" and
"X".

Using the play sequence you can calculate the score for the play as follows: for every maximal consecutive "O"s block, add the square of its length (the number
of characters "O") to the score. For example, if your play can be encoded as "OOXOOOXXOO",
then there‘s three maximal consecutive "O"s block "OO", "OOO",
"OO", so your score will be 22?+?32?+?22?=?17.
If there are no correct clicks in a play then the score for the play equals to 0.

You know that the probability to click the i-th (1?≤?i?≤?n) click
correctly is pi.
In other words, the i-th character in the play sequence has piprobability
to be "O", 1?-?pi to
be "X". You task is to calculate the expected score for your play.

Input

The first line contains an integer n (1?≤?n?≤?105)
— the number of clicks. The second line contains n space-separated real numbersp1,?p2,?...,?pn (0?≤?pi?≤?1).

There will be at most six digits after the decimal point in the given pi.

Output

Print a single real number — the expected score for your play. Your answer will be considered correct if its absolute or relative error does not exceed 10?-?6.

Sample test(s)

input

3
0.5 0.5 0.5

output

2.750000000000000

input

4
0.7 0.2 0.1 0.9

output

2.489200000000000

input

5
1 1 1 1 1

output

25.000000000000000

Note

For the first example. There are 8 possible outcomes. Each has a probability of 0.125.

  • "OOO" ?→? 32?=?9;
  • "OOX" ?→? 22?=?4;
  • "OXO" ?→? 12?+?12?=?2;
  • "OXX" ?→? 12?=?1;
  • "XOO" ?→? 22?=?4;
  • "XOX" ?→? 12?=?1;
  • "XXO" ?→? 12?=?1;
  • "XXX" ?→? 0.

So the expected score is 

/**
 * Created by ckboss on 14-9-3.
 */
import java.util.*;

public class N {
    public static void main(String[] args){
       Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        double ans=0,pre=0,now=0;
        for(int i=1;i<=n;i++)
        {
            now=in.nextDouble();
            pre=pre*now;
            ans+=2*pre+now;
            pre=pre+now;
        }
        System.out.println(ans);
    }
}

Codeforces 235B. Let's Play Osu!

时间: 2024-10-20 02:48:08

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

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 B Let&#39;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 #i

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