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 ...
随机推荐
- (转)iPhone 判断UITableView 滚动到底部
UITableView is a subclass of UIScrollView, and UITableViewDelegate conforms to UIScrollViewDelegate. ...
- C++类訪问控制及继承
一.C++类的訪问控制有三类:public,protected和private. 类訪问控制符 类成员可被哪些对象訪问 public 1.类的成员函数.2.类对象.3.友元.4.子类成员函数 prot ...
- python进阶之路之文件处理
Python之文件处理 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !imp ...
- 阿里云 RDS 怎么保证高可用性
RDS在系统构建之初,从网络到硬件再到系统都是基于高可用设计,他可以做到故障30秒无缝转移,对应用完全透明. 当一个数据库实例发生故障时, 另一个会立即顶上,而且对应用是完全透明的.你无需变更应用的连 ...
- 虚拟现实,增强现实,VR,AR
现在的热点不止VR,还有AR和披着MR.HR.CR外衣的各种高级AR们,所以比较着一起说.以下知乎上一网友观点,放几条结论:1.近期(未来两三年)看,VR能火,AR尚待成熟: 2.VR设备中,插片式是 ...
- 新闻滚动marquee标签
先上代码: <marquee behavior="" direction="up" onMouseOver="this.stop()" ...
- (转).net程序员转战android第三篇---登录模块之静态登录
这一篇我将分2个部分记录登录界面,第一部分是静态登录, 这部分将如何从界面布局.控件使用.文件关系.数据验证.登陆实现等5小块记录. 第二部分是动态登录,这块会基于上面的4小块,在数据验证不是静态数据 ...
- WebApi实现跨域功能
在配置文件的system.webServer节点中加入以下配置信息 <httpProtocol> <customHeaders> <add name="Acce ...
- UILabel 的使用,属性详解
·UILable是iPhone界面最基本的控件,主要用来显示文本信息. ·常用属性和方法有: .创建 CGRect rect = CGRectMake(, , , ); UILabel *label ...
- 无法捕获的异常:MissingMethodException
今天一个同事发布站点,一直出现一些稀奇古怪的问题,各种各样的异常都有,根据这些异常去排查代码,都完全正常,很让人郁闷,因为代码里可能出异常的地方都记录了程序日志,所以他一直没去排查系统里的“应用程序日 ...