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 ...
随机推荐
- Java之Map
Map 是一种把键对象和值对象映射的集合,它的每一个元素都包含一对键对象和值对象. Map没有继承于Collection接口 从Map集合中检索元素时,只要给出键对象,就会返回对应的值对象. code ...
- JDBC中Statement接口提供的execute、executeQuery和executeUpdate之间的区别
Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语句所产生的内容决定. 方法execut ...
- Oracle insert update 时间处理
24小时表示方法:to_date(’ ::’,’yyyy-mm-dd hh24:mi:ss’) 12小时表示方法:to_date(’ ::’,’yyyy-mm-dd hh:mi:ss’) ','S75 ...
- Html5 Canvas 实现滚动的图片
今天一直在找html5 canvas的使用实例.想画一张地图,再画个小车在上面跑.运气好找到了一个大神写的js代码.该代码实现了图片的左右来回滚动,现在粘贴在博客里记录一下: <html> ...
- 泛型 Field 和 SetField 方法 (LINQ to DataSet)
LINQ to DataSet 为 DataRow 类提供用于访问列值的扩展方法:Field 方法和 SetField 方法.这些方法使开发人员能够更轻松地访问列值,特别是 null 值.DataSe ...
- 《31天成为IT服务达人》之技能篇硬件维护技能概要
server维护技能 server硬件作为应用软件部署的基础平台,是基础架构中最为核心的设备.一旦server出现问题就会影响业务的正常开展.因此,server的运维管理对于企业整个IT运维管理 ...
- js+css实现模态层效果
在做web前端的时候,有些时候会涉及到模态层,在此提供一种实现思路.希望对大家实用.先贴效果吧: 模态层效果 以下说说在写模态层的时候的思路:通过可配置的參数width,height,title以及c ...
- [Node.js] Use "prestart" in scripts
Usually we run : npm start to start an app, then we we might call other script to do something: npm ...
- HDU 4588 Count The Carries 计算二进制进位总数
点击打开链接 Count The Carries Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java ...
- 新闻滚动marquee标签
先上代码: <marquee behavior="" direction="up" onMouseOver="this.stop()" ...