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≤), 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 ≤M,N≤, ≤K≤.
 
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

 
Sample Output
Case #:
Case #:
Hint
The precise answer in the first test case is about 3.56790123.
Source
 
题意大致是:进行K次染色,每次染色会随机选取一个以(x1,y1),(x2,y2)为一组对角的子矩阵进行染色,求K次染色后染色面积的期望值(四舍五入)。
 
对于这道题的话,首先要考虑的是进行一次选择时的期望。求期望的方法为单独考虑每一格所能获得的期望,然后将所有格的期望相加即为答案。
对于每一个所能获得的期望,即要计算所有包含这一格的个数ans,除于总的选择方案tot

此时我们的问题转向了如何计算A[x.y]上

由题目描述,一次染色中可能的操作有n^2*m^2种

计算A[x,y]时,我们可以把整个矩阵做如下拆分

当前计算的方块为[x,y],即图中编号为5的部分

将其他部分拆分成图上8个区域,则可得到以下关系

对于一种染色方案能够覆盖方块[x,y]时
①[x1,y1]取在区域1内时,[x2,y2]可以在5、、、9四个区域内任取;
②[x1,y1]取在区域2内时,[x2,y2]可以在4、、、、、9六个区域内任取;
③[x1,y1]取在区域3内时,[x2,y2]可以在4、、、8四个区域内任取;
④[x1,y1]取在区域4内时,[x2,y2]可以在2、、、、、9六个区域内任取;
⑤[x1,y1]取在区域5内时,[x2,y2]可以在所有区域内任取;
⑥[x1,y1]取在区域6内时,[x2,y2]可以在1、、、、、8六个区域内任取;
⑦[x1,y1]取在区域7内时,[x2,y2]可以在2、、、6四个区域内任取;
⑧[x1,y1]取在区域8内时,[x2,y2]可以在1、、、、、6六个区域内任取;
⑨[x1,y1]取在区域1内时,[x2,y2]可以在1、、、5四个区域内任取;

计算出这个格子的概率p后,总的答案加上 1-pow(1-p,k),得到最后的答案

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<stdlib.h>
#include<queue>
using namespace std;
#define ll long long
int m,n,k;
int main()
{
int t;
int ac=;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&k);
double ans=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
double tmp=;
tmp=tmp+(double)(i-)*(j-)*(n-i+)*(m-j+);//
tmp=tmp+(double)(i-)*(n-i+)*m;//
tmp=tmp+(double)(i-)*(m-j)*(n-i+)*j;//
tmp=tmp+(double)(m-j)*n*j;//
tmp=tmp+(double)n*m;//
tmp=tmp+(double)(j-)*n*(m-j+);//
tmp=tmp+(double)(n-i)*(j-)*i*(m-j+);//
tmp=tmp+(double)(n-i)*i*m;//
tmp=tmp+(double)(n-i)*(m-j)*i*j;// double p=tmp/n/n/m/m;
ans=ans+-pow((-p),k); }
}
printf("Case #%d: ",++ac);
printf("%d\n",int(ans+0.5));
}
return ;
}

hdu 5245 Joyful(期望的计算,好题)的更多相关文章

  1. HDU 5245 Joyful (期望)

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

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

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

  3. HDU 5245 Joyful(期望)

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

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

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

  5. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

  6. HDU 5984 数学期望

    对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...

  7. HDU 2096 小明A+B --- 水题

    HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...

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

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

  9. Joyful HDU - 5245 概率问题

    Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks ...

随机推荐

  1. java Color

    通过16进制颜色值获取颜色方法:Color.decode("#E0EEEE"); --后继续补充

  2. How to face setbacks

    I’ve been in a bad mood since I started on the American Accent. I became even more upset when I adde ...

  3. ios按钮点击时的灰色框

    a,button,input,textarea{-webkit-tap-highlight-color: rgba(0,0,0,0;)}

  4. WPF DataGrid 之数据绑定--实例2

    1.前台Grid定义 <!--数据绑定--> <DataGrid Grid.Row="1" Name="gridOne" Margin=&qu ...

  5. (转)AspNetPager查询分页问题(点击页码,不再是查询后的数据集)viewstate解决

    public string SQL = "select * from Memorandum";       protected void Page_Load(object send ...

  6. AVT Vimba与OpenCV环境配置

    近来,由于项目需求,需要使用AVT的一款相机采集图像并进行相应的算法处理.环境的配置过程较为复杂,特此记录,以做备忘.也给有需要的小伙伴们一些key point的分享. 搭建环境:Windows7 + ...

  7. (原)ubuntu16重装显卡驱动后,torch中的问题

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6030232.html 参考网址: https://github.com/torch/cutorch/i ...

  8. HDU 5044 离线LCA算法

    昨天写了HDU 3966 ,本来这道题是很好解得,结果我想用离线LCA 耍一把,结果发现离线LCA 没理解透,错了好多遍,终得AC ,这题比起 HDU 3966要简单,因为他不用动态查询.但是我还是错 ...

  9. 数据链路层-点对点协议PPP

    在通信质量较差的年代,在数据链路层使用可靠传输协议曾是一个好的办法.因此,能实现可靠传输的高级数据链路控制HDLC(High-Level Data Link Control)就称为当时比较流行的数据链 ...

  10. 实验八 sqlite数据库操作

    实验报告 课程名称 基于Android平台移动互联网开发 实验日期 2016年5月3日 实验项目名称 SQLite数据库操作 实验地点 S30010 实验类型 □验证型    √设计型    □综合型 ...