hdu 5245 2015 上海邀请赛(期望值 数学概率)



Joyful

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


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,N500 1K20 .
 

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.
 

这个题 着实 上头,   随机取 两个值,  求期望值 ,完蛋 求期望 公式不会了0- 0   期望值 高中题 ╮(╯▽╰)╭ 

公式不会  又不是很理解  caodan  

看了网上大牛的解释, 好吧  

思路:

1 两层for 循环扫描 每一个 每一个概率相等 

2 求可以覆盖的区域


这个图  从大神那搞得,   以 5 为特例  求 覆盖5的 区域   根据分布原理  两个相乘

1. 第一个选择  1 区域 和则 第二个 右下 5-6-8-9 都可以

2 .第一个选择  9 区域 和则 第二个 左上 5-4-1-2 都可以

3. 第一个选择  7 区域 和则 第二个 右上 5-6-3-2 都可以

4 .第一个选择  3 区域 和则 第二个 左下 5-4-7-8都可以

5. 第一个选择  2 区域 和则 第二个 二三行 4-5-6-7-8-9 都可以

6 .第一个选择  4 区域 和则 第二个 二三列 2-5-8-9-6-3 都可以

7 .第一个选择  8 区域 和则 第二个 一二行 1-2-3-4-5-6 都可以

8. 第一个选择  6 区域 和 则 第二个 一二列 1-2-4-5-7-8都可以

9. 第一个选择  5 区域 则 第二个 任意个地方都可以 即 1-2-3-4-5-6-7-8-9 


因此 我们 只需要 按照上面的思路 求覆盖  (x,y) 这个点 9步 就可以

                    p=n*m;// 他自己 周围 8个方向都可以  即m*n;
                    p+=(i-1)*(j-1)*(n-i+1)*(m-j+1);// 1  5-6-8-9
                    p+=(i-1)*(m-j)*j*(n-i+1);//   3  4-5-7-8
                    p+=(j-1)*(n-i)*i*(m-j+1);//  7  2-3-5-6
                    p+=(n-i)*(m-j)*i*j;//  9   1-2-4-5
                    p+=(i-1)*m*(n-i+1);// 正上  2  4-5-6-7-8-9
                    p+=(m-j)*n*j;//正右  6   1-2-4-5-7-8
                    p+=(n-i)*m*i;// 正下  8  1-2-3-4-5-6
                    p+=(j-1)*n*(m-j+1);//正左 4  2-3-5-6-7-8

 


代码:

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>

using namespace std;
typedef long long ll;

int main()
{
    int T,i,j,k;
    double n,m;// n,m 要double  后面有p/(n*m*n*m) 防止误差
    while(cin>>T)
    {
        int count=1;
        while(T--)
        {
            scanf("%lf %lf %d",&n,&m,&k);
            double p,ans=0;
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++)
                {
                    p=n*m;// 他自己 周围 8个方向都可以  即m*n;
                    p+=(i-1)*(j-1)*(n-i+1)*(m-j+1);// 1  5-6-8-9
                    p+=(i-1)*(m-j)*j*(n-i+1);//   3  4-5-7-8
                    p+=(j-1)*(n-i)*i*(m-j+1);//  7  2-3-5-6
                    p+=(n-i)*(m-j)*i*j;//  9   1-2-4-5
                    p+=(i-1)*m*(n-i+1);// 正上  2  4-5-6-7-8-9
                    p+=(m-j)*n*j;//正右  6   1-2-4-5-7-8
                    p+=(n-i)*m*i;// 正下  8  1-2-3-4-5-6
                    p+=(j-1)*n*(m-j+1);//正左 4  2-3-5-6-7-8
                    p/=(n*n*m*m);
                    ans+=1-(pow(1-p,k));
                }
            }
            printf("Case #%d: %d\n",count++,int(ans+0.5));
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值