Ultraviolet A 11605-lights inside a 3D Grid
Question Link
Given a 3D nxmxp mesh with a light on each grid, now two points are randomly selected each time. The two points constitute the switch light in the middle of the cube, q: What are the expectations of bright lights in the grid after K Steps?
Train of Thought: For the probability problem, separate the X, Y, and Z axes to calculate the number of cases where Xi, Yi, and Zi can be selected for each vertex, then, we can calculate the probability of dividing by the sum based on the multiplication principle, and then the problem is K times. For K times, the probability of each open operation is P, the total situation is ΣK1PI(1?P)K?IIIf it is an odd number, it is easy to simplify the combination formula:
= "(1?P+P)K? (1?P?P)K)/2
= "(1? (1? 2P)K)/2
Then the expectation for each vertex is the answer.
Code:
#include <cstdio>#include <cstring>#include <cmath>int t, n, m, p, K;double cal(double P) { return (1 - pow(1 - 2 * P, K)) / 2;}double solve() { double ans = 0; for (int i = 1; i <= n; i++) {for (int j = 1; j <= m; j++) { for (int k = 1; k <= p; k++) {int x = (n - i + 1) * i;int y = (m - j + 1) * j;int z = (p - k + 1) * k;double P = (2 * x * 1.0 - 1) / (m * n * p) * (2 * y - 1) / (m * n * p) * (2 * z - 1);ans += cal(P); }} } return ans;}int main() { int cas = 0; scanf("%d", &t); while (t--) {scanf("%d%d%d%d", &n, &m, &p, &K);printf("Case %d: %.10lf\n", ++cas, solve()); } return 0;}