概率问题,像是概率论上学的均匀分布,是不是呢,忘了。。。
概率同面积有关系,我写的各种搓,然后此题格式十分变态,=前有的时候俩空格,有的时候一个空格。代码各种搓。
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <cmath> 5 #include <algorithm> 6 using namespace std; 7 #define PI 3.141592653 8 #define eps 1e-9 9 int main() 10 { 11 int t,cas = 1; 12 double n,m,d,r,S; 13 double t11,t12,t13,t14,t21,t22,t23,t24,t31,t32,t33,t34; 14 double a1,a2,a3,a4; 15 scanf("%d",&t); 16 while(t--) 17 { 18 scanf("%lf%lf%lf%lf",&n,&m,&d,&r); 19 S = n*m*d*d; 20 t11 = (d-r/2)*(d-r/2); 21 t12 = 2*(d-r/2)*r/2; 22 t13 = 0.25*PI*(r/2)*(r/2); 23 t14 = (r/2)*(r/2) - t13; 24 t21 = (d-r/2)*(d-r); 25 t22 = (d-r/2)*r + (d-r)*r/2; 26 t23 = 0.5*PI*(r/2)*(r/2); 27 t24 = 2*(r/2)*(r/2) - t23; 28 t31 = (d-r)*(d-r); 29 t32 = 4*(d-r)*r/2; 30 t33 = PI*(r/2)*(r/2); 31 t34 = r*r - t33; 32 if(n == 1&&m == 1) 33 { 34 a1 = S; 35 a2 = 0; 36 a3 = 0; 37 a4 = 0; 38 } 39 else if(n == 1) 40 { 41 a1 = 2*(d-r/2)*d + (m-2)*(d-r)*d; 42 a2 = S - a1; 43 a3 = 0; 44 a4 = 0; 45 } 46 else if(m == 1) 47 { 48 a1 = 2*(d-r/2)*d + (n-2)*(d-r)*d; 49 a2 = S - a1; 50 a3 = 0; 51 a4 = 0; 52 } 53 else 54 { 55 a1 = 4*t11 + 2*(n-2+m-2)*t21 + (n-2)*(m-2)*t31; 56 a2 = 4*t12 + 2*(n-2+m-2)*t22 + (n-2)*(m-2)*t32; 57 a3 = 4*t13 + 2*(n-2+m-2)*t23 + (n-2)*(m-2)*t33; 58 a4 = 4*t14 + 2*(n-2+m-2)*t24 + (n-2)*(m-2)*t34; 59 } 60 printf("Case %d: ",cas++); 61 printf("Probability of covering 1 tile = %.4f%% ",a1*100/S); 62 printf("Probability of covering 2 tiles = %.4f%% ",a2*100/S); 63 printf("Probability of covering 3 tiles = %.4f%% ",a4*100/S); 64 printf("Probability of covering 4 tiles = %.4f%% ",a3*100/S); 65 printf(" "); 66 } 67 return 0; 68 }