LightOJ - 1284 (probability)

Title Source: the Click
title meaning: a three-dimensional space of points have state of the switch. The number of point of asking open state expectations.
After calculating the number of light switches x, y, z are in the range 1-100. certainly not end points is calculated. Since only two states to consider the number of combination related. Can be calculated from the point cut is included several times.
p is the probability of the selected point, the interval chosen to be so by 1-i ix ii 2 but may be calculated by subtracting 1 can be repeated.
After using the binomial theorem (a + b) ^ n and (ab) ^ n is calculated. Only been selected odd number of points is summed ON state.

#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<istream>
#include<vector>
#include<stack>
#include<map>
#include<algorithm>
#include<queue>
#define MAX_len 50100*4
using namespace std;
typedef long long ll;
double dp[110][105][105];
int C(int n)
{
    return n*(n-1)/2;
}
double quickpow(double a,int n)
{
    double res=1.0;
    while(n)
    {
        if(n&1)
        {
            res*=a;
        }
        n>>=1;
        a*=a;
    }
    return res;
}
int main()
{
    int T;
    scanf("%d",&T);
    int yy=1;
    while(T--)
    {
        memset(dp,0,sizeof(dp));
        int x,y,z,k,i,j;
        scanf("%d %d %d %d",&x,&y,&z,&k);
        double ans=0;
        for(i=1;i<=x;i++)
        {
            for(j=1;j<=y;j++)
            {
                for(int hh=1;hh<=z;hh++)
                {
                     double p=0.0;
                     p=1.0*((x-i+1)*i*2.0-1)/(x*x*1.0);
                     p*=1.0*((y-j+1)*(j)*2.0-1)/(y*y*1.0);
                     p*=1.0*((z-hh+1)*(hh)*2.0-1)/(z*z*1.0);
                    ans+=(1-quickpow(1-2*p,k))*1.0/(2.0);
                }
            }
        }
        printf("Case %d: %.10lf\n",yy++,ans);
    }
    return 0;
}



Published 72 original articles · won praise 19 · views 7504

Guess you like

Origin blog.csdn.net/weixin_43958964/article/details/104361002