poj 3440 Coin Toss

本文提供了一道来自POJ在线评测系统的简单题目的解答思路及代码实现。该题目要求计算不同瓷砖覆盖概率,通过精确数学运算避免整型越界问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

简单题目 但是由于忽视了int越界 贡献了一次wa

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<cmath>
#define LL long long

using namespace std;
const double PI=acos(-1.0);
int main()
{
   int T;
   double sum,s1,s2,s3,s4;
   scanf("%d",&T);
   for(int w=1;w<=T;++w)
   {
       double n,m,l,d;
       cin>>n>>m>>l>>d;
       sum=n*m*l*l;
       s1=1.0*n*m*(l-d)*(l-d);
       s4=1.0*(n-1)*(m-1)*PI*(1.0*d/2)*(1.0*d/2);
       s2=(1.0*(n-1)*m*l+1.0*(m-1)*n*l)*d-2.0*(n-1)*(m-1)*d*d;
       s3=(n-1)*(m-1)*d*d-s4;
       s1=sum-s2-s3-s4;
       printf("Case %d:\n",w);
       printf("Probability of covering 1 tile  = %.4f%%\n",100.0*s1/sum);
       printf("Probability of covering 2 tiles = %.4f%%\n",100.0*s2/sum);
       printf("Probability of covering 3 tiles = %.4f%%\n",100.0*s3/sum);
       printf("Probability of covering 4 tiles = %.4f%%\n",100.0*s4/sum);
       if(w!=T)
       printf("\n");
   }
   return 0;
}

  

转载于:https://www.cnblogs.com/liulangye/archive/2012/07/26/2610669.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值