hdu5245---Joyful(期望)

Problem Description
Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like an M×N matrix. The wall has M×N squares in all. In the whole problem we denotes (x,y) to be the square at the x-th row, y-th column. Once Sakura has determined two squares (x1,y1) and (x2,y2), she can use the magical tool to paint all the squares in the sub-matrix which has the given two squares as corners.

However, Sakura is a very naughty girl, so she just randomly uses the tool for K times. More specifically, each time for Sakura to use that tool, she just randomly picks two squares from all the M×N squares, with equal probability. Now, kAc wants to know the expected number of squares that will be painted eventually.

Input
The first line contains an integer T(T≤100), denoting the number of test cases.

For each test case, there is only one line, with three integers M,N and K.
It is guaranteed that 1≤M,N≤500, 1≤K≤20.

Output
For each test case, output ”Case #t:” to represent the t-th case, and then output the expected number of squares that will be painted. Round to integers.

Sample Input

2
3 3 1
4 4 2

Sample Output

Case #1: 4
Case #2: 8

Hint
The precise answer in the first test case is about 3.56790123.

Source
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest

Recommend
We have carefully selected several similar problems for you: 5244 5243 5242 5241 5240

考慮每個格子被塗到的概率,最後把概率加起來就行

/*************************************************************************
    > File Name: hdu5245.cpp
    > Author: ALex
    > Mail: [email protected] 
    > Created Time: 2015年05月28日 星期四 13時33分13秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

int main() {
    int t, icase = 1;
    scanf("%d", &t);
    while (t--) {
        int n, m, k;
        scanf("%d%d%d", &n, &m, &k);
        double ans = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= m; ++j) {
                LL ways = (LL)(i - 1) * (i - 1) * m * m;
                ways += (LL)(j - 1) * (j - 1) * n * n;
                ways += (LL)(n - i) * (n - i) * m * m;
                ways += (LL)(m - j) * (m - j) * n * n;
                ways -= (LL)(i - 1) * (i - 1) * (j - 1) * (j - 1);
                ways -= (LL)(i - 1) * (i - 1) * (m - j) * (m - j);
                ways -= (LL)(j - 1) * (j - 1) * (n - i) * (n - i);
                ways -= (LL)(n - i) * (n - i) * (m - j) * (m - j);
                LL sum = (LL)m * m * n * n;
                double p = ways * 1.0 / sum;
                double tmp = 1;
                for (int l = 1; l <= k; ++l) {
                    tmp *= p;
                }
                ans += (1 - tmp);
            }
        }
        printf("Case #%d: %.0f\n", icase++, ans);
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章