hdu 5245 Joyful(期望)

Joyful

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1243    Accepted Submission(s): 546

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

代码较挫,

 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4
 5 using namespace std;
 6
 7 #define LL long long
 8
 9 long long C(LL  a,LL b)
10 {
11     return a * b * a * b;
12 }
13 int main()
14 {
15     long long T,m,n,k;
16     int cas = 0;
17     scanf("%lld",&T);
18     while(T--)
19     {
20         LL sum;
21         double ans=0, p;
22         scanf("%lld%lld%lld",&m,&n,&k);
23         for(LL i=0; i<m; i++)
24         {
25             for(LL j=0; j<n; j++)
26             {
27                sum = C(i,n)+C((m-i-1),n)+C(j,m)+C((n-j-1),m);
28                sum = sum - C(i,j) - C(i,(n-j-1)) - C((m-i-1),j ) - C((m-i-1),(n-j-1)) ;
29                p = sum * 1.0 / C(m,n);
30
31 double tmp=1;
32                for (LL jj = 1; jj <= k; ++jj)
33                     tmp *= p;
34                ans=ans+1-tmp;
35             }
36         }
37         printf("Case #%d: %.0f\n",++cas,ans);
38     }
39     return 0;
40 }
时间: 2024-10-13 08:00:04

hdu 5245 Joyful(期望)的相关文章

HDU 5245 Joyful (期望)

题意:进行K次染色,每次染色会随机选取一个以(x1,y1),(x2,y2)为一组对角的子矩阵进行染色,求K次染色后染色面积的期望值(四舍五入). 析:我们可以先求出每个格子的期望,然后再加起来即可.我们可以把格子进行划分,然后再求概率. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cst

hdu 5245 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

HDU 5245 Joyful (概率题 求期望)

Joyful Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 478    Accepted Submission(s): 209 Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a

HDU 5245 Joyful (2015年上海大都赛J题,概率)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5245 题意: 给定一个n*m的矩形,由n*m个格子组成,我们可以选k次,每次可以选择的两个格子 这两个格子作为矩形的对角线可以确定一个矩形,这个矩形里的所有小格子都会被覆 盖,求k次后,被覆盖的格子的个数的期望. 分析: 棋盘被覆盖的格子数的期望 = 每个格子被覆盖的概率的和. 每次选择的方案有n*m*n*m种. 格子坐标为(i,j)被覆盖的方案数为: tot = 2*(2*(i*j*(n-i+1)

HDU 5245 Joyful

传送门 Joyful Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 781 Accepted Submission(s): 339 Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a w

J - Joyful HDU - 5245 (概率)

题目链接: J - Joyful  HDU - 5245 题目大意:给你一个n*m的矩阵,然后你有k次涂色机会,然后每一次可以选定当前矩阵的一个子矩阵染色,问你这k次用完之后颜色个数的期望. 具体思路:颜色个数的期望等于每一个方块单独的期望加起来,就是总的期望. 对于当前的方块的期望,我们先计算这个方块不会出现的概率,就是当前的(x,y),先计算出当前的两个点在他周围四整块的出现的概率,但是这样四个角会重复计算,再去掉就好了. AC代码: 1 #include<bits/stdc++.h> 2

hdu 4586 (概率+期望)

http://acm.hdu.edu.cn/showproblem.php?pid=4586 大致题意:有一个骰子有n个面,掷到每一个面的概率是相等的,每一个面上都有相应的钱数.其中当你掷到m个面之一时,你有多掷一次的机会.问最后所得钱数的期望. 思路:设投掷第一次的期望是p,那么第二次的期望是m/n*p,第三次的期望是 (m/n)^2*p......第N次的期望是(m/n)^(N-1)*p. 那么这些期望之和便是答案.之前也是想到这,但不知道如何处理无限的情况.当时脑卡了,这不是赤裸裸的等比数

HDU 5345 Joyful(概率题求期望)

D - Joyful Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like an $M \times N$ matrix. The wal

HDU 5245 上海大都会 J题 (概率期望)

这道题的概率可以单独考虑每个格子对期望的贡献值.因为其实每个格子是否被选都可以认为是独立的,单独一个格子贡献的期望为1*(该格子K次被选的概率),所以答案其实就是每个格子K次被选中的概率之和. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define LL long long using namespace std; int main(){ LL