poj 3440 Coin Toss(概率)

http://poj.org/problem?id=3440


大致题意:给出一个n*m的格子,每个格子的边长为t,随意抛一枚硬币并保证硬币的圆心在格子里或格子边上,硬币的直径为c,求硬币覆盖格子的个数的概率。


思路:高中的概率题,ms是几何概型。根据分别覆盖1,2,3,4个格子时圆心可分部的面积比上总面积就是答案。


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#define LL long long
#define _LL __int64
#define eps 1e-8
#define PI acos(-1.0)
using namespace std;

const int INF = 0x3f3f3f3f;
const int maxn = 10;

double ans[6];

int main()
{
	int test;
	scanf("%d",&test);
	for(int item = 1; item <= test; item++)
	{
		double n,m,t,c;
		scanf("%lf %lf %lf %lf",&n,&m,&t,&c);
		
		//WA ,把fm定义成了int型
		double fm = n*m*t*t;

		ans[1] = (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[3] = (c*c - PI*(c/2)*(c/2) )*(n-1)*(m-1);

		ans[4] = PI*(c/2)*(c/2)*(n-1)*(m-1);

		ans[2] = fm - ans[1] - ans[3] - ans[4];

		printf("Case %d:\n",item);
		for(int i = 1; i <= 4; i++)
		{
			if(i == 1)
				printf("Probability of covering 1 tile  = %.4f%%\n",ans[1]*100.0/fm);
			else
				printf("Probability of covering %d tiles = %.4f%%\n",i,ans[i]*100.0/fm);
		}
		printf("\n");
	}
	return 0;
}


你可能感兴趣的:(数学,概率)