HDU5245 Joyful

http://acm.hdu.edu.cn/showproblem.php?pid=5245

题目大意:一个大矩形由n*m个小方块组成,一个人每次选两个小方块,他可以对以这两个方块为顶点的矩形面积内的小方块上色,他一共可选k次,现在求被上色的小方块数目的期望

在做这道题的时候能考虑到是期望概率的问题,但是怎么算也得不到样例,看完题解后才明白,欠缺。

借鉴的题解:
每个格子可以被重复选,因此可以把每一个小方块选不选当做一个独立事件,所以我们算出每个小方块对总期望的贡献值就行了,直接算不好算,考虑算每个小方块一次不被选的概率p,这个算起来就方便很多,不妨以当前点为中心,那么只有四种情况,被选的两个小方块同在中心的上下左右,不过这样会重复,四个角相当于被算了两次,再把它们减掉一次,这样求出来的是当前点一次不会被上色的情况数,除以总情况数(m * n * m * n)就是当前方块一次不会被上色的概率,再乘k次,就是k次这个方块都不被上色的概率,用1减则为选k次这个方块被上色的概率,只需要把每个方块选k次后被上色的概率累加即可,情况数中间可能会爆int,用__int64

此代码在杭电提交C++超时用G++则AC

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
__int64 t,i,j,cas,ii,n,m,k;
double sum,num;
scanf("%I64d",&t);
{
for(ii=1;ii<=t;ii++)
{
scanf("%I64d%I64d%I64d",&m,&n,&k);
sum=num=0;
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
num+=(i-1)*n*(i-1)*n;
num+=(j-1)*m*(j-1)*m;
num+=(m-i)*n*(m-i)*n;
num+=(n-j)*m*(n-j)*m;
num-=(i-1)*(j-1)*(i-1)*(j-1);
num-=(i-1)*(n-j)*(i-1)*(n-j);
num-=(m-i)*(j-1)*(m-i)*(j-1);
num-=(m-i)*(n-j)*(m-i)*(n-j);
num/=n*m*n*m;
sum+=1.0-pow(num,k);
}
}
printf("Case #%I64d: %.0lf\n",ii,sum);
}
}
return 0 ;
}

时间: 2024-11-10 01:08:39

HDU5245 Joyful的相关文章

HDU 5345 Joyful(概率题求期望)

D - Joyful Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like an $M \times N$ matrix. The wal

hdu 5245 Joyful(期望)

Joyful Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1243    Accepted Submission(s): 546 Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a

HDU 5245 Joyful

传送门 Joyful Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 781 Accepted Submission(s): 339 Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a w

HDU 5245 Joyful (概率题 求期望)

Joyful Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 478    Accepted Submission(s): 209 Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a

J - Joyful HDU - 5245 (概率)

题目链接: J - Joyful  HDU - 5245 题目大意:给你一个n*m的矩阵,然后你有k次涂色机会,然后每一次可以选定当前矩阵的一个子矩阵染色,问你这k次用完之后颜色个数的期望. 具体思路:颜色个数的期望等于每一个方块单独的期望加起来,就是总的期望. 对于当前的方块的期望,我们先计算这个方块不会出现的概率,就是当前的(x,y),先计算出当前的两个点在他周围四整块的出现的概率,但是这样四个角会重复计算,再去掉就好了. AC代码: 1 #include<bits/stdc++.h> 2

HDU 5245 Joyful (期望)

题意:进行K次染色,每次染色会随机选取一个以(x1,y1),(x2,y2)为一组对角的子矩阵进行染色,求K次染色后染色面积的期望值(四舍五入). 析:我们可以先求出每个格子的期望,然后再加起来即可.我们可以把格子进行划分,然后再求概率. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cst

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

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

HDU 5245 Joyful (2015年上海大都赛J题,概率)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5245 题意: 给定一个n*m的矩形,由n*m个格子组成,我们可以选k次,每次可以选择的两个格子 这两个格子作为矩形的对角线可以确定一个矩形,这个矩形里的所有小格子都会被覆 盖,求k次后,被覆盖的格子的个数的期望. 分析: 棋盘被覆盖的格子数的期望 = 每个格子被覆盖的概率的和. 每次选择的方案有n*m*n*m种. 格子坐标为(i,j)被覆盖的方案数为: tot = 2*(2*(i*j*(n-i+1)

The Importance of Money in Life

What were you taught about money as you were growing up?something like "Money doesn't grow on trees", or "Money is the root of all evil",or maybe "all rich people are greedy"? Well,how do you expect to become a success financ