POJ 3440 Coin Toss(概率)

题目链接

概率问题,像是概率论上学的均匀分布,是不是呢,忘了。。。

概率同面积有关系,我写的各种搓,然后此题格式十分变态,=前有的时候俩空格,有的时候一个空格。代码各种搓。

 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:\n",cas++);
61         printf("Probability of covering 1 tile  = %.4f%%\n",a1*100/S);
62         printf("Probability of covering 2 tiles = %.4f%%\n",a2*100/S);
63         printf("Probability of covering 3 tiles = %.4f%%\n",a4*100/S);
64         printf("Probability of covering 4 tiles = %.4f%%\n",a3*100/S);
65         printf("\n");
66     }
67     return 0;
68 }

 

转载于:https://www.cnblogs.com/naix-x/p/3207548.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值