HDU 5245 期望概率

Joyful

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


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(T100), 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 1M,N5001K20.
 

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
题意:一个大矩形由M*N个小方块组成,一个人每次选两个小方块,他可以对以这两个方块为顶点的矩形面积内的小方块上色,他一共可选k次,现在求被上色的小方块数目的期望

每个块可以重复选择,每个点可以重复染色,染几次就算几次。第一个方块的选择有n*m种,第二个方块有n*m种选择,所以共有n*m*n*m种选择。

定义运算p(a,b)=a*b*a*b;

若对于一个方块a[i,j]不被选择的情况共有p(i-1,N)+p(M-i,N)+p(j-1,M)+p(N-j,M)-p(i-1,j-1)-p(M-i,j-1)-p(N-j,i-1)-p(N-j,M-i)种情况,所以可以算出对于一次选择他不被染色的概率,进而求出K次选择他不被染色的概率。对每个方块进行这样的操作,即可算出期望。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll p(ll a,ll b)
{
    return a*a*b*b;
}

int main()
{
    int T;
    scanf("%d",&T);
    int cas=1;
    while(T--)
    {
        ll M,N,K;
        scanf("%lld%lld%lld",&M,&N,&K);
        ll ans,sum;
        double q=0;
        double res=0;
        sum=p(M,N);
        for(ll i=1;i<=M;i++)
        {
            for(ll j=1;j<=N;j++)
            {
                ans=0;
                ans+=p(i-1,N);
                ans+=p(M-i,N);
                ans+=p(j-1,M);
                ans+=p(N-j,M);
                ans-=p(i-1,j-1);
                ans-=p(M-i,j-1);
                ans-=p(N-j,i-1);
                ans-=p(N-j,M-i);
               // printf("%lld\n",ans);
                q=1.0*ans/sum;
               // printf("%lf\n",q);
                double tmp=1;
                for(ll i=0;i<K;i++)
                    tmp*=q;
                res+=1-tmp;
            }
        }
        printf("Case #%d: %.0lf\n",cas++,res);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值