Ultraviolet A 11605-lights inside a 3D grid (probability + mathematics)

Source: Internet
Author: User
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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.