高中概率的几何概型,这也叫作题,不过输出真的很坑。
题目大意:
n*m个边长为t的正方形组成的矩形。往矩形上抛一个直径为c的硬币,问覆盖1,2,3,4个矩形的概率为多少?
解题思路:
计算出覆盖1,2,3,4个矩形时硬币圆心可以在的位置区域。就能求出概率了~
下面是代码:
#include <set> #include <map> #include <queue> #include <math.h> #include <vector> #include <string> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> #define eps 1e-6 #define pi acos(-1.0) #define inf 107374182 #define inf64 1152921504606846976 #define lc l,m,tr<<1 #define rc m + 1,r,tr<<1|1 #define iabs(x) ((x) > 0 ? (x) : -(x)) #define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (SIZE)) #define clearall(A, X) memset(A, X, sizeof(A)) #define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE)) #define memcopyall(A, X) memcpy(A , X ,sizeof(X)) #define max( x, y ) ( ((x) > (y)) ? (x) : (y) ) #define min( x, y ) ( ((x) < (y)) ? (x) : (y) ) using namespace std; int main() { int T,case1=1; double n,m,t,c,ans[4]; scanf("%d",&T); while(T--) { scanf("%lf%lf%lf%lf",&n,&m,&t,&c); ans[0]=(t-c/2)*(t-c/2)*4 + (t-c)*(t-c/2)*(2*m+2*n-8) + (t-c)*(t-c)*(n-2)*(m-2); //覆盖一个方格时硬币圆心可以在的位置 ans[2] = (c*c - pi*(c/2)*(c/2) )*(n-1)*(m-1); ans[3] = pi*(c/2)*(c/2)*(n-1)*(m-1); ans[1] = n*m*t*t - ans[0] - ans[2] - ans[3]; printf("Case %d:\n",case1++); printf("Probability of covering 1 tile = %.4f%%\n",ans[0]*100.0/(n*m*t*t)); for(int i=1;i<4;i++) { printf("Probability of covering %d tiles = %.4f%%\n",i+1,ans[i]*100.0/(n*m*t*t)); } puts(""); } return 0; }
POJ 3440 Coin Toss,布布扣,bubuko.com
原文地址:http://blog.csdn.net/lin375691011/article/details/38434789