分析和思路可以看我的一篇总结性文章 UVa 11605
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <deque>
#include <algorithm>
#include <string>
#define REP(i , a) for(int i=1;i<=a;i++)
using namespace std;
double handle(double a , double i) { return (a*a - (i-1)*(i-1) - (a-i)*(a-i))/a/a; }
double pow_double(double a , int n)
{
if(!n) return 1;
double res = pow_double(a , n/2);
res = res*res;
if(n&1) res *= a;
return res;
}
int main()
{
int t;
cin>>t;
for(int Case=1;Case<=t;Case++)
{
int a , b , c , k;
cin>>a>>b>>c>>k;
double res =0 ;
REP(i , a) REP(j , b) REP(l , c)
{
double p = handle(a , i)*handle(b , j)*handle(c , l);
res += (1 - pow_double(1-2*p , k))/2;
}
printf("Case %d: %.10lf\n",Case , res);
}
return 0;
}