UVA 11605 Lights inside a 3d Grid

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
using namespace std;

double GetP(int x, int N)
{
    return (2.0*x*(N-x+1)-1)/N/N;
}

double P2E(double p, int k)
{
    return (1-pow(1-2*p, k))/2;
}

double GetE(int N, int M, int P, int K)
{
    double px,py,pz;
    double e=0;
    for(int x=1;x<=N;x++)
    {
        px = GetP(x, N);
        for(int y=1;y<=M;y++)
        {
            py = GetP(y, M);
            for(int z=1;z<=P;z++)
            {
                pz = GetP(z, P);
                e += P2E(px*py*pz, K);
            }
        }
    }
    return e;
}

int main()
{
    int N,M,P,K;
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        scanf("%d%d%d%d", &N,&M,&P,&K);
        printf("Case %d: %.10lf\n", i, GetE(N,M,P,K));
    }
    return 0;
}

 

posted @ 2015-10-06 02:52  屠一刀  阅读(211)  评论(0编辑  收藏  举报