poj 3440 Coin Toss 概率问题

这题主要是推导数学公式!!!

将概率问题转化为圆心所在的面积!

代码如下:

 

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#define pi acos(-1.0)
using namespace std;
int main()
{
    int i=0,k;
    double a1,a2,a3,a4,sum,r,m,n,t,c;
    cin>>k;
    while(k--){
        cin>>m>>n>>t>>c;
        r=c/2.0;
        sum=m*n*t*t;
        a2=c*((t-c)*n+c)*(m-1)+c*((t-c)*m+c)*(n-1);
        a3=(c*c-pi*r*r)*(m-1)*(n-1);
        a4=pi*r*r*(m-1)*(n-1);
        a1=sum-a2-a3-a4;
        printf("Case %d:\n",++i);
        printf("Probability of covering 1 tile  = %.4f%%\n",100*a1/sum);
        printf("Probability of covering 2 tiles = %.4f%%\n",100*a2/sum);
        printf("Probability of covering 3 tiles = %.4f%%\n",100*a3/sum);
        printf("Probability of covering 4 tiles = %.4f%%\n",100*a4/sum);
        printf("\n");
    }
}
View Code

 

 

 

posted @ 2013-08-02 21:32  _随心所欲_  阅读(217)  评论(0编辑  收藏  举报