POJ 3440 Coin Toss(求概率)

题目链接

题意 :把硬币往棋盘上扔,分别求出硬币占1,2,3,4个格子的时候的概率。

思路 : 求出公式输出,不过要注意输出格式,我还因为输入的时候用了int类型错了好几次。。。。。


 1 //3440
2 #include <stdio.h>
3 #include <string.h>
4 #include <iostream>
5 #include <math.h>
6 #define PI acos(-1.0)
7
8 using namespace std ;
9
10 int main()
11 {
12 int k;
13 double a1,a2,a3,a4,sum;
14 double c,m,n,t;
15 scanf("%d",&k) ;
16 for(int i = 1 ; i <= k ; i++){
17 scanf("%lf %lf %lf %lf",&m,&n,&t,&c) ;
18 sum = m*n*t*t;
19 a1 = (t-c)*(t-c)*n*m+(c*(t-c)+c*c/4.0)*4+c*(t-c)*(n+m-4) ;
20 a2 = (m-1)*n*t*c+(n-1)*m*t*c-2*(m-1)*(n-1)*c*c;
21 a3 = (m-1)*(n-1)*c*c*(1-PI/4);
22 a4 = (m-1)*(n-1)*c*c*PI/4;
23 printf("Case %d:\n",i);
24 printf("Probability of covering 1 tile = %.4f%%\n",100*a1/sum);
25 printf("Probability of covering 2 tiles = %.4f%%\n",100*a2/sum);
26 printf("Probability of covering 3 tiles = %.4f%%\n",100*a3/sum);
27 printf("Probability of covering 4 tiles = %.4f%%\n",100*a4/sum);
28 printf("\n");
29 }
30 return 0 ;
31 }

时间: 2024-10-19 14:16:29

POJ 3440 Coin Toss(求概率)的相关文章

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&g

POJ 3440 Coin Toss

高中概率的几何概型,这也叫作题,不过输出真的很坑. 题目大意: n*m个边长为t的正方形组成的矩形.往矩形上抛一个直径为c的硬币,问覆盖1,2,3,4个矩形的概率为多少? 解题思路: 计算出覆盖1,2,3,4个矩形时硬币圆心可以在的位置区域.就能求出概率了~ 下面是代码: #include <set> #include <map> #include <queue> #include <math.h> #include <vector> #incl

[ACM] POJ 3440 Coin Toss (几何概率)

Coin Toss Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3019   Accepted: 817 Description In a popular carnival game, a coin is tossed onto a table with an area that is covered with square tiles in a grid. The prizes are determined by t

【POJ 3440】 Coin Toss(概率公式)

[POJ 3440] Coin Toss(概率公式) Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3591   Accepted: 957 Description In a popular carnival game, a coin is tossed onto a table with an area that is covered with square tiles in a grid. The prizes ar

poj 3440 (概率)

链接:poj 3440 题意:在m*n的网格盘上,每个格子大小都是t*t, 现将一个直径为c的硬币扔在向网格盘上, 求硬币覆盖1,2,3,4个格的概率分别为多少 注:圆心只可能落在在网格盘上 分析:问题可转化为求覆盖1,2,3,4个格硬币圆心活动的面积 分别推出公式即可求解 注意输出格式... #include<stdio.h> #include<math.h> #define PI 4.0*atan(1.0) int main() { int T,k; double m,n,t,

[ACM] poj 2096 Collecting Bugs (概率DP,期望)

Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 2026   Accepted: 971 Case Time Limit: 2000MS   Special Judge Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material st

POJ 3071 Football(简单 概率DP)

Football 原文链接:http://blog.csdn.net/xuechelingxiao/article/details/38520105 大意:2^n 个球队进行单场淘汰赛,每两只球队之间比赛会有胜负的概率,问最后谁夺冠的概率最大. 思路:简单的概率DP问题,主要是怎么处理哪两个球队比赛的问题. DP方程为 dp[i][j] = ∑(dp[i-1][j]*dp[i-1][k]*p[j][k]); //dp[i][j]表示第 i 轮的时候,第 j 支队伍赢的概率.. 对于其中位运算,可

POJ 2299 Ultra-QuickSort(归并排序求逆序对数)

题目地址:POJ 2299 今天下午的多校看来没有白做...实在做不出题闲着无聊看小白鼠学会了个归并排序.哈哈. 归并排序简单地说其实就是先分成一个二叉树直至单个,然后依次从最底层不断进行合并,逆序对数就是在合并的过程中,加入后面的那段中到了比他大的时候,那后面的那些就都是比他大的,都是逆序对数,所以直接加上即可.网上资料很多,就不细说了..用了分治的思想. 自己根据理解写的代码,考虑的太不全面了..又调了好长时间... 代码如下: #include <algorithm> #include

POJ 2540 半平面交求可行区域面积

Hotter Colder Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2343   Accepted: 981 Description The children's game Hotter Colder is played as follows. Player A leaves the room while player B hides an object somewhere in the room. Player