LightOJ 1284

**题意:**给你一个长宽高为x,y,z的长方体,里面每个格子放了灯,再给你k次选取任意长方体形状的区块,对其内所有灯开或关操作,初始为关,问亮灯数量的期望值。 **题解:**首先考虑选取区块的概率,使某个灯在被选取的区块内要求为三维的每个坐标都在选取范围内如 \(x1<=x0<=x2\) 一个维度为选中的情况总数为$$Q_{x} = x^2 - (a-1)^2 - (x-a)^2 $$ 所以一个格点被选到的概率为\(p=frac{Q_{x}Q_{y}Q_{z}}{{x^2}{y^2}{z^2}} \) 再者考虑奇数次被开启是开 偶数次开启是关,所以 $$p_{奇}=sum_{i mod 2 = 1}^{n}{C_{k}^{i}p^{i}(1-p)^{k-i}} $$ $$p_{偶}=sum_{2 | i}^{n}{C_{k}^{i}p^{i}(1-p)^{k-i}}$$ 写出偶数项后可发现两个函数和就是二项式公式 \(p_{奇} + p_{偶} = (1 - p + p)^k = 1\) 再考虑到奇数这个特殊性质 \(p_{偶} - p_{奇} = (1 - p - p)^k \) 然后求得 $$p_{奇}=frac{1-(1-2p)^k}{2}$$ 然后期望值就等于全部选取方案下的亮灯概率和。
/** @Date    : 2016-10-25-19.26
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link :
* @Version : $
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
#define LL long long
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+2000;

double cal(double a, double x)
{
return (x * x - (a-1) * (a-1) - (x-a) * (x-a))/(x * x);
}


int main()
{
int T;
int cnt = 0;
cin >> T;
while(T--)
{
double x, y, z, K;
scanf("%lf%lf%lf%lf", &x, &y, &z, &K);
double ans = 0;
for(int i = 1; i <= x; i++)
{
for(int j = 1; j <= y; j++)
{
for(int k = 1; k <= z; k++)
{
double p = cal((double)i, x)*cal((double)j, y)*cal((double)k, z);
ans += (1 - pow(1 - 2 * p, K)) / 2;
}
}
}
printf("Case %d: %.10lf ", ++cnt, ans);
}
return 0;
}