hdu 5245 Joyful(期望的计算,好题)
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.
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≤.
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.
Case #:
Case #:
The precise answer in the first test case is about 3.56790123.
此时我们的问题转向了如何计算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(期望的计算,好题)的更多相关文章
- HDU 5245 Joyful (期望)
题意:进行K次染色,每次染色会随机选取一个以(x1,y1),(x2,y2)为一组对角的子矩阵进行染色,求K次染色后染色面积的期望值(四舍五入). 析:我们可以先求出每个格子的期望,然后再加起来即可.我 ...
- HDU 5245 Joyful(概率题求期望)
D - Joyful Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- HDU 5245 Joyful(期望)
http://acm.hdu.edu.cn/showproblem.php?pid=5245 题意: 给出一个n*m的矩阵格子,现在有k次操作,每次操作随机选择两个格子作为矩形的对角,然后将这范围内的 ...
- J - Joyful HDU - 5245 (概率)
题目链接: J - Joyful HDU - 5245 题目大意:给你一个n*m的矩阵,然后你有k次涂色机会,然后每一次可以选定当前矩阵的一个子矩阵染色,问你这k次用完之后颜色个数的期望. 具体思路 ...
- HDU 1248 寒冰王座(全然背包:入门题)
HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
- HDU 2096 小明A+B --- 水题
HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...
- HDU 5245 上海大都会 J题 (概率期望)
这道题的概率可以单独考虑每个格子对期望的贡献值.因为其实每个格子是否被选都可以认为是独立的,单独一个格子贡献的期望为1*(该格子K次被选的概率),所以答案其实就是每个格子K次被选中的概率之和. #in ...
- Joyful HDU - 5245 概率问题
Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks ...
随机推荐
- http2.0 相对于 http1.1的优势
1.http2.0完全是多路复用的,只需一个连接就可实现并行 可以将不同的请求夹杂在一起,只需一个连接就能加载一个页面. 2.可以让服务器将响应主动推动到客户端缓存中 当浏览器请求一个网页时,服务器除 ...
- Unity 单元测试(PLUnitTest工具)
代码测试的由来 上几个星期上面分配给我一个装备系统,我经过了几个星期的战斗写完90%的代码. 后来策划告诉我需求有一定的改动,我就随着策划的意思修改了代码. 但是测试(Xu)告诉我装备系统很多功能都用 ...
- python scrapy 基础
scrapy是用python写的一个库,使用它可以方便的抓取网页. 主页地址http://scrapy.org/ 文档 http://doc.scrapy.org/en/latest/index.ht ...
- 一个提供jsp免费空间的站点
EATJ美国JSP虚拟主机商提供免费jsp空间申请,50M空间,每月3G的流量限制,支持Java5.0/6.0.PHP.CGI.Perl.SSI等,提供2个MySQL数据库,Tomcat v5.5/v ...
- [Cycle.js] Introducing run() and driver functions
Currently the code looks like : // Logic (functional) function main() { return { DOM: Rx.Observable. ...
- 用消息在Win32控制台程序多线程间进行通讯
#include <stdio.h> #include <windows.h> //#include <iostream> //#include <pro ...
- Windows Server 2008搭建域控制器《转载51CTO.com》
Windows Server 2008搭建域控制器 引入 在小型网络中,管理员通常独立管理每一台计算机,如最为常用的用户管理.但当网络规模扩大到一定程度后,如超过 10 台计算机,而每台计算机上有 1 ...
- Socket学习笔记
..........(此处略去万万字)学习中曲折的过程不介绍了,直接说结果 我的学习方法,问自己三个问题,学习过程将围绕这三个问题进行 what:socket是什么 why:为什么要使用socket ...
- JavaScript操作剪贴板(转)
IE是第一个支持与剪贴板相关的事件,以及通过JavaScript访问剪贴板数据的浏览器.IE的实现成为了某种标准,不仅Safari 2.Chrome和Firefox 3也都支持类似的事件和剪贴板(Op ...
- 作为java应届生,面试求职那点事
找工作两星期多了.心情不爽,写点记录打发时间. 嘘~~自己的破事: 刚毕业,也过了实习,本理所应当的留在公司转正.可是为了谈了两年的女朋友回家见面.一切都顺利进行,妈妈也开心给了一万见面礼,一切都以 ...