[topcoder]CoinReversing

http://community.topcoder.com/stat?c=problem_statement&pm=11473&rd=14543

简单的概率题。那道题想了想就出来了。每一轮中所有硬币都有相同的概率变化成另一面。

public class CoinReversing
{
    public double expectedHeads(int N, int[] a)
    {
        double heads = N;
        double tails = 0;
        
        for (int i = 0; i < a.length; i++)
        {
            heads = ((N-a[i])*heads + a[i]*tails) / N;
            tails = N - heads;
        }
        return heads;
    }
}

  

posted @ 2013-10-02 23:40  阿牧遥  阅读(165)  评论(0编辑  收藏  举报