题意:
在一个三维的空间,每个点都有一盏灯,开始全是关的.
现在每次随机选两个点,把两个点之间的全部点,开关都按一遍;
问k次过后开着的灯的期望数量;
思路:
一个点如果被包到所选空间里,那么说明我们选的两个点,横坐标在这个点两侧,纵坐标在这个点两侧,高坐标在这个点两侧;
根据这个,我们可以求出每一个操作,这个点被包进去的概率;
然后用等比数列求和公式,推导出被包进去奇数次的概率;
然后把每个点算出来的概率加起来:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int x,y,z,n;
double total;
double cul(int a, int b) {
//求在某一维,两个点不在同一侧的概率
return 1.0 - 1.0 * ((a - 1) * (a - 1) + (b - a) * (b - a)) / (b * b);
}
int main() {
int t;
int cas = 1;
scanf("%d",&t);
while(t--) {
double ans = 0.0;
scanf("%d%d%d%d", &x,&y,&z,&n);
total = 1.0 * x * y * z * x * y * z;
for(int i = 1; i <= x; i++)
for(int j = 1; j <= y; j++)
for(int k = 1; k <= z; k++) {
double p = cul(i,x) * cul(j,y) * cul(k,z);//被覆盖的概率
ans += 0.5 - 0.5 * pow(1 - 2 * p, 1.0 * n);//被覆盖奇数次的概率
}
printf("Case %d: %.10lf\n",cas++, ans);
}
}