hdu5245---Joyful(期望),joyful

來源:互聯網
上載者:User

hdu5245---Joyful(期望),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: 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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.