标签:
最近电脑老死机,而且都是我东西快写完没有保存的时候。。。w(゜Д゜)w
题目大意:有 n 个球,每次把一个区间染成黑色,求期望多少次把所有球染黑
设
这道题还有一点就是要保留15位小数,所以窝写了发python(其中有个错,就是定义超过一维数组的时候不能写a[[0]*M]*N
,而是应写成a[[0 for x in range(M)]for y in range(N)])
结果没有python…(真是一个悲伤的故事…
转java QAQ(换行要写成 \r\n,只写 \n 会PE…
import java.util.Scanner;
import java.io.*;
import java.math.BigDecimal;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
long [][][]f = new long[55][2][2600];
BigDecimal []E = new BigDecimal[55];
for (int i = 0;i < 55;i ++)
for (int j = 0;j < 2;j ++)
for (int k = 0;k < 2600;k ++) f[i][j][k] = new Long(0);
for (int i = 0;i < 55;i ++) E[i] = new BigDecimal("0");
f[0][0][0] = (long)1;
for (int i = 0;i <= 50;i ++)
for (int j = 0;j <= i * (i + 1) / 2;j ++)
for (int k = i + 1;k <= 50;k ++)
{
f[k][0][j + (k - i) * (k - i - 1) / 2] += f[i][1][j];
f[k][1][j + (k - i) * (k - i - 1) / 2] += f[i][0][j];
}
for (int i = 1;i <= 50;i ++)
for (int j = 0;j <= i;j ++)
for (int k = 0;k <= j * (j + 1) / 2;k ++)
{
if ((k + (i - j) * (i - j + 1) / 2) / (i * (i + 1) / 2) == 1) continue;
BigDecimal p = new BigDecimal("1.0"),a = new BigDecimal(k + (i - j + 1) * (i - j) / 2),b = new BigDecimal (i * (i + 1) / 2);
p = p.subtract(a.divide(b,50,BigDecimal.ROUND_HALF_UP));
BigDecimal temp = new BigDecimal(f[j][1][k] - f[j][0][k]);
E[i] = E[i].add(temp.divide(p,50,BigDecimal.ROUND_HALF_UP));
}
int T = in.nextInt(),x;
for (int i = 1;i <= T;i ++)
{
x = in.nextInt();
System.out.printf("%.15f\r\n",E[x]);
}
}
}
标签:
原文地址:http://blog.csdn.net/beginendzrq/article/details/51331954