题意 :把硬币往棋盘上扔,分别求出硬币占1,2,3,4个格子的时候的概率。
思路 : 求出公式输出,不过要注意输出格式,我还因为输入的时候用了int类型错了好几次。。。。。
1 //3440 2 #include <stdio.h> 3 #include <string.h> 4 #include <iostream> 5 #include <math.h> 6 #define PI acos(-1.0) 7 8 using namespace std ; 9 10 int main() 11 { 12 int k; 13 double a1,a2,a3,a4,sum; 14 double c,m,n,t; 15 scanf("%d",&k) ; 16 for(int i = 1 ; i <= k ; i++){ 17 scanf("%lf %lf %lf %lf",&m,&n,&t,&c) ; 18 sum = m*n*t*t; 19 a1 = (t-c)*(t-c)*n*m+(c*(t-c)+c*c/4.0)*4+c*(t-c)*(n+m-4) ; 20 a2 = (m-1)*n*t*c+(n-1)*m*t*c-2*(m-1)*(n-1)*c*c; 21 a3 = (m-1)*(n-1)*c*c*(1-PI/4); 22 a4 = (m-1)*(n-1)*c*c*PI/4; 23 printf("Case %d: ",i); 24 printf("Probability of covering 1 tile = %.4f%% ",100*a1/sum); 25 printf("Probability of covering 2 tiles = %.4f%% ",100*a2/sum); 26 printf("Probability of covering 3 tiles = %.4f%% ",100*a3/sum); 27 printf("Probability of covering 4 tiles = %.4f%% ",100*a4/sum); 28 printf(" "); 29 } 30 return 0 ; 31 }