码迷,mamicode.com
首页 > 其他好文 > 详细

hdu5245---Joyful(期望)

时间:2015-05-28 14:08:27      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:期望

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: zchao1995@gmail.com 
    > 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;
}

hdu5245---Joyful(期望)

标签:期望

原文地址:http://blog.csdn.net/guard_mine/article/details/46121457

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!