Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like an M×NM×N matrix. The wall has M×NM×N squares in all. In the whole problem we denotes (x,y)(x,y) to be the square at the xx-th row, yy-th column. Once Sakura has determined two squares (x1,y1)(x1,y1) and (x2,y2)(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 KKtimes. More specifically, each time for Sakura to use that tool, she just randomly picks two squares from all the M×NM×N squares, with equal probability. Now, kAc wants to know the expected number of squares that will be painted eventually.

InputThe first line contains an integer TT(T≤100T≤100), denoting the number of test cases.

For each test case, there is only one line, with three integers M,NM,N and KK. 
It is guaranteed that 1≤M,N≤5001≤M,N≤500, 1≤K≤201≤K≤20. 
OutputFor each test case, output ''Case #t:'' to represent the tt-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.

题意:

给出一个M*N的矩阵,从其中任意的选两个格子,将以两个格子为对角的矩形染色。这样的操作重复k次,问会被涂色的格子数的期望值。

分析:

期望值说白了就是执行完上述操作后,计算最有可能涂了多少个格子。

看了网上的题解才明白,我们只需要计算每一个格子可能被选中的概率,

期望值E(x)=x1*p1 + x2*p2 + .....  + xn*pn;

在这里我们把每1个格子看做独立事件,所以这里的x1=x2=.....=xn=1,

所以对于本题,期望值 E(x)=p1 + p2 + .....  + pn;

解题:

现在问题就简化成了求 每一个格子 被选中的概率,再累加即可。

先看一张图:

假设现在我们求5这个点被涂色的概率,怎样可以让他染上色呢?

选点(x1,y1)和 (x2,y2)构成的矩形包含5这个点即可。

在矩阵中选两个点的总情况数 是 m*n * m*n

那么选点有9种情况:

1、若(x1,y1)在区域1,则(x2,y2)可以在区域5、6、8、9

2、若(x1,y1)在区域3,则(x2,y2)可以在区域4、5、7、8

3、若(x1,y1)在区域7,则(x2,y2)可以在区域2、3、5、6

4、若(x1,y1)在区域9,则(x2,y2)可以在区域1、2、4、5

5、若(x1,y1)在区域2,则(x2,y2)可以在区域4、5、6、7、8、9

6、若(x1,y1)在区域4,则(x2,y2)可以在区域2、3、5、6、8、9

7、若(x1,y1)在区域6,则(x2,y2)可以在区域1、2、4、5、7、8

8、若(x1,y1)在区域8,则(x2,y2)可以在区域1、2、3、4、5、6

9、若(x1,y1)在区域5,则(x2,y2)可以在任意区域

当前这个点被染色的概率就是这9种情况之概率和。
---------------------

参考博客:https://blog.csdn.net/winter2121/article/details/71082686

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e3+10;
const ll mod = 1e9+7;
const double pi = acos(-1.0);
const double eps = 1e-8;
int main() {
ll T, k;
double n, m;
scanf("%lld",&T);
for( ll cas = 1; cas <= T; cas ++ ) {
scanf("%lf %lf %lld",&m,&n,&k);
double sum = n*m*n*m, ans = 0; //sum:所有的情况种数,ans:期望值
for( ll i = 1; i <= m; i ++ ) {
for( ll j = 1; j <= n; j ++ ) { //对每一个点算贡献值
double p = 0; //点(i,j)被选中的情况数
        //另外一个点在区域1,3,5,7
p += (i-1)*(j-1)*(m-i+1)*(n-j+1);
p += (i-1)*(n-j)*(m-i+1)*j;
p += (m-i)*(j-1)*i*(n-j+1);
p += (m-i)*(n-j)*i*j;
        //另外一个点在区域2,4,6,8 
p += (i-1)*1*(m-i+1)*n;
p += 1*(j-1)*m*(n-j+1);
p += 1*(n-j)*m*j;
p += (m-i)*1*i*n;
        //另外一个点在区域5
p += m*n;
        //点(i,j)被选中的概率
p = (p*1.0)/sum;
ans += 1-pow(1-p,k);
}
}
printf("Case #%lld: %.0f\n",cas,ans);
}
return 0;
}

  

  

Joyful HDU - 5245 概率问题的更多相关文章

  1. J - Joyful HDU - 5245 (概率)

    题目链接: J - Joyful  HDU - 5245 题目大意:给你一个n*m的矩阵,然后你有k次涂色机会,然后每一次可以选定当前矩阵的一个子矩阵染色,问你这k次用完之后颜色个数的期望. 具体思路 ...

  2. HDU - 5245 概率

    JoyfulHDU - 5245 题目大意:有N*M个正方形,进行k次涂色,每次会随机的选两个正方形作为一个矩形区域的顶点,然后把这个区域内的涂色,最后问k次之后,预计被涂了色的正方形有几个(也就是数 ...

  3. HDU 5985 概率

    n种硬币各有cnt[i]枚,每轮下其有p[i]概率保留,问各种硬币只有它存活到最后一轮的概率. 设k轮后i硬币存活概率$a[i][k]=(1-p^k_i)^{cnt[i]}$ 则最后只有第i种硬币存活 ...

  4. HDU 5245 Joyful(概率题求期望)

    D - Joyful Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  5. HDU 5245 Joyful(期望)

    http://acm.hdu.edu.cn/showproblem.php?pid=5245 题意: 给出一个n*m的矩阵格子,现在有k次操作,每次操作随机选择两个格子作为矩形的对角,然后将这范围内的 ...

  6. hdu 5245 Joyful(期望的计算,好题)

    Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to pain ...

  7. HDU 5245 Joyful (期望)

    题意:进行K次染色,每次染色会随机选取一个以(x1,y1),(x2,y2)为一组对角的子矩阵进行染色,求K次染色后染色面积的期望值(四舍五入). 析:我们可以先求出每个格子的期望,然后再加起来即可.我 ...

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

    这道题的概率可以单独考虑每个格子对期望的贡献值.因为其实每个格子是否被选都可以认为是独立的,单独一个格子贡献的期望为1*(该格子K次被选的概率),所以答案其实就是每个格子K次被选中的概率之和. #in ...

  9. hdu 1203 概率+01背包

    I NEED A OFFER! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

随机推荐

  1. 日常用shell命令

    递归更改文件夹权限:chmod -R 767 文件名 mac启动apache sudo apachectl start/restart mac停止apache sudo apachectl stop ...

  2. Linux升级GCC

    升级原因 测试需要使用DOClever,下载了最新的node8.11,运行node 时候报错 [root@app_test bin]# node www module.js:681 return pr ...

  3. 【iOS】iOS main() 简介

    C 语言编写的程序,其执行入口都是 main(). 用 Objective-C 语言编写的程序也是这样. main.m 中的代码如下: int main(int argc, char * argv[] ...

  4. golang文档、中文、学习文档

    Golang中文文档地址 http://zh-golang.appspot.com/doc/ Golang非英文文档地址: https://github.com/golang/go/wiki/NonE ...

  5. 【python-Django开发】Django 配置MySQL数据库讲解!!!

    官方文档请阅读:https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-db-api-drivers 配置MySQL数据库 1. 新建M ...

  6. 2019中山纪念中学夏令营-Day9[JZOJ](第六次模拟赛)

    Begin (题目的排序方式:Unkown其实是按心情排的) 异或:(摘自百度百科) 异或(xor)是一个数学运算符.它应用于逻辑运算.异或的数学符号为“⊕”,计算机符号为“xor”.其运算法则为: ...

  7. 算法与数据结构基础 - 字典树(Trie)

    Trie基础 Trie字典树又叫前缀树(prefix tree),用以较快速地进行单词或前缀查询,Trie节点结构如下: //208. Implement Trie (Prefix Tree)clas ...

  8. Spring Boot + Security + JWT 实现Token验证+多Provider——登录系统

    首先呢就是需求: 1.账号.密码进行第一次登录,获得token,之后的每次请求都在请求头里加上这个token就不用带账号.密码或是session了. 2.用户有两种类型,具体表现在数据库中存用户信息时 ...

  9. 简单认识Nginx---负载均衡

    中大型项目都会考虑到分布式,前面几篇文章着重介绍了数据处理的技术集群.今天来研究一下关于服务器的负载均衡–Nginx.他除了静态资源的处理外还有可以决定将请求置于那台服务上. Nginx的安装 点我下 ...

  10. RabbitMQ的基本介绍及与Spring整合

    一,场景回顾 ​ 最近做电商购物项目,在分布式中搜索服务,商品详情服务都是独立的模块.那么有一个问题就是: 商品的原始数据保存在数据库中,增删改查都在数据库中完成. 搜索服务数据来源是索引库,如果数据 ...