源代码
#include <stdio.h>
#include <math.h>
int main()
{
const double PI=acos(-1.0);
double area[5];
double n,m,t,c;
int cas,i,j;
double d11,d12,d13,d21,d22;
scanf("%d",&cas);
for(i=1;i<=cas;i++)
{
scanf("%lf%lf%lf%lf",&n,&m,&t,&c);
d11=(t-c/2)*(t-c/2)*4;
d12=(t-c/2)*(t-c)*(n+m-4)*2;
d13=(t-c)*(t-c)*(n*m-(2*(n+m)-4));
d21=c*(t-c/2)*((m-1)*2+(n-1)*2);
d22=c*(t-c)*((m-1)*n+(n-1)*m-(m-1)*2-(n-1)*2);
area[0]=t*t*n*m;
area[1]=d11+d12+d13;
area[2]=d21+d22;
area[3]=(c*c-PI*(c/2)*(c/2))*(n-1)*(m-1);
area[4]=PI*c*c/4*(n-1)*(m-1);
printf("Case %d:\n",i);
for(j=1;j<=4;j++)
{
if(j==1)
printf("Probability of covering %d tile = %.4lf%%\n",j,area[j]/area[0]*100);
else
printf("Probability of covering %d tiles = %.4lf%%\n",j,area[j]/area[0]*100);
}
printf("\n");
}
return 0;
}
|