首页 > 代码库 > poj 3440 (概率)

poj 3440 (概率)

链接:poj 3440

题意:在m*n的网格盘上,每个格子大小都是t*t,

现将一个直径为c的硬币扔在向网格盘上,

求硬币覆盖1,2,3,4个格的概率分别为多少

注:圆心只可能落在在网格盘上

分析:问题可转化为求覆盖1,2,3,4个格硬币圆心活动的面积

分别推出公式即可求解

注意输出格式、、、


#include<stdio.h>
#include<math.h>
#define PI 4.0*atan(1.0)
int main()
{
    int T,k;
    double m,n,t,c;
    scanf("%d",&T);
    for(k=1;k<=T;k++){
        printf("Case %d:\n",k);
        scanf("%lf%lf%lf%lf",&m,&n,&t,&c);
        double area=m*n*t*t;
        double tile1=(m+n)*2*(t-c)*(c/2)+(c/2)*(c/2)*4+(t-c)*(t-c)*m*n;
        double tile2=((m-1)+(n-1))*2*c*(c/2)+((m-1)*n+(n-1)*m)*(t-c)*c;
        double tile3=(m-1)*(n-1)*(c*c-PI*(c/2)*(c/2));
        double tile4=(m-1)*(n-1)*PI*(c/2)*(c/2);
        printf("Probability of covering 1 tile  = %.4lf%%\n",tile1/area*100);
        printf("Probability of covering 2 tiles = %.4lf%%\n",tile2/area*100);
        printf("Probability of covering 3 tiles = %.4lf%%\n",tile3/area*100);
        printf("Probability of covering 4 tiles = %.4lf%%\n",tile4/area*100);
        printf("\n");
    }
    return 0;
}


poj 3440 (概率)