编程介的小学生 2017-11-12 15:42 采纳率: 20.5%
浏览 526
已结题

Endless Spin

Problem Description

I spin it again and again,and throw it away finally.
So now I have a row of n ball,named from 1 to n,each ball is white initially.
At each step I randomly chose a interval [l, r] and paint all ball in this interval to black.
It means every interval have a equal chance of being chosen.
And I'll stop if all ball are black.What is the expected steps before I stop?

Input
The first line contains integer T(1<=T<=50). Denoting the number of the test cases.
Then T lines follows, each line contains an integer n (1<=n<=50).

Output
For each test cases,print the answer in a line.
Print the answer rounded to 15 decimal places.

Sample Input
3
1
2
3

Sample Output
1.000000000000000
2.000000000000000
2.900000000000000

  • 写回答

1条回答 默认 最新

  • 夜恋幽幽 2018-08-17 10:30
    关注

    #include
    #include
    #include
    #include
    #define G(x) (((x+1)*(x))>>1)
    #define ll long long
    using namespace std;
    int n;
    ll f[55][2555][2];
    int main()
    {
    int ca;
    scanf("%d",&ca);
    while(ca--)
    {
    scanf("%d",&n);
    memset(f,0,sizeof(f));
    f[0][0][0]=1;
    for(int i=1;i<=n;i++)
    for(int j=0;j<i;j++)
    for(int s=G(i-j-1);s<=G(i);s++)
    for(int b=0;b<=1;b++)
    f[i][s][b]+=f[j][s-G(i-j-1)][b^1];

    double ans=0,tot=G(n);
    for(int i=1;i<=n;i++)
    for(int s=0;s<=G(i);s++)
    if(f[i][s][1]-f[i][s][0]!=0)
    ans+=tot*(f[i][s][1]-f[i][s][0])/(tot-s-G(n-i));
    printf("%.15lf\n",ans);

    }
    return 0;
    }

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试