Joyful
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 478 Accepted Submission(s): 209
However, Sakura is a very naughty girl, so she just randomly uses the tool for times. More specifically, each time for Sakura to use that tool, she just randomly picks two squares from all the squares, with equal probability. Now, kAc wants to know the expected number of squares that will be painted eventually.
For each test case, there is only one line, with three integers and .
It is guaranteed that ,.
The main idea of the title is to give a matrix of m*n, select a random sub-matrix for coloring each time, and ask the expected value of the number of colored grids after k times of coloring.
Idea: The expected value of the number of dyed grids = the sum of the probability of each grid being dyed , so first calculate the probability of a grid being dyed, and then double-cycle to accumulate the probability of each grid.
如何求一个格子被染色的概率?要么该矩阵在这个格子的左边,要么在上,下或者右边,那么如果以j值(列)来看,exp:如果最小j值和最大j值都在格子的左边,是不是不用管i值,矩阵直接在格子左边?依此类推,那么j值矩阵不覆盖的概率为p1=((j-1)*(j-1)+(n-j)*(n-j)/(n*n);依次类推出i值矩阵不覆盖的概率p2,然后该格子被覆盖的概率为 p=(1-p1)*(1-p2),再用1-p是没有覆盖该格子的概率,然后k次方就是k次都没有覆盖该格子的概率,用1-(1-p)^k就是一个格子被染色的概率。
为什么不直接求该格子被染色的概率,而是直接1-减去p?假设该格子被覆盖的概率为p那么该格子被染色的概率就要用多项式来统计,非常麻烦...
代码如下:
#include<cstdio>
#include<algorithm>
using namespace std;
int m,n;
double pp(int i,int m)
{
double t1=i-1,t2=m-i;
return 1.0-(t1*t1+t2*t2)/(m*m);
}
double ans(int i,int j,int k)
{
double x=1-pp(i,m)*pp(j,n),p=1;
for(int i=1;i<=k;i++)
p=p*x;
return 1-p;
}
int main()
{
int i,j,k,t;
scanf("%d",&t);
for(int ll=1;ll<=t;ll++)
{
double res=0;
scanf("%d %d %d",&m,&n,&k);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
res=res+ans(i,j,k);
}
printf("Case #1: %.0lf\n",res);
}
return 0;
}