博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3440--Coin Toss(几何上的概率)
阅读量:4691 次
发布时间:2019-06-09

本文共 3891 字,大约阅读时间需要 12 分钟。

Coin Toss
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 3946   Accepted: 1076

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 the number of tiles covered by the coin when it comes to rest: the more tiles it covers, the better the prize. In the following diagram, the results from five coin tosses are shown:

In this example:

  • coin 1 covers 1 tile
  • coin 2 covers 2 tiles
  • coin 3 covers 3 tiles
  • coin 4 covers 4 tiles
  • coin 5 covers 2 tiles

Notice that it is acceptable for a coin to land on the boundary of the playing area (coin 5). In order for a coin to cover a tile, the coin must cover up a positive area of the tile. In other words, it is not enough to simply touch the boundary of the tile. The center of the coin may be at any point of the playing area with uniform probability. You may assume that (1) the coin always comes to a rest lying flat, and (2) the player is good enough to guarantee that the center of the coin will always come to rest on the playing area (or the boundary).

The probability of a coin covering a certain number of tiles depends on the tile and coin sizes, as well as the number of rows and columns of tiles in the playing area. In this problem, you will be required to write a program which computes the probabilities of a coin covering a certain number of tiles.

Input

The first line of input is an integer specifying the number of cases to follow. For each case, you will be given 4 integers m, n, t, and c on a single line, separated by spaces. The playing area consists of m rows and n columns of tiles, each having side length t. The diameter of the coin used is c. You may assume that 1 <= m, n <= 5000, and 1 <= c < t <= 1000.

Output

For each case, print the case number on its own line. This is followed by the probability of a coin covering 1 tile, 2 tiles, 3 tiles, and 4 tiles each on its own line. The probability should be expressed as a percentage rounded to 4 decimal places. Use the format as specified in the sample output. You should use double-precision floating-point numbers to perform the calculations. "Negative zeros" should be printed without the negative sign. 
Separate the output of consecutive cases by a blank line.

Sample Input

35 5 10 37 4 25 2010 10 10 4

Sample Output

Case 1:Probability of covering 1 tile  = 57.7600%Probability of covering 2 tiles = 36.4800%Probability of covering 3 tiles = 1.2361%Probability of covering 4 tiles = 4.5239%Case 2:Probability of covering 1 tile  = 12.5714%Probability of covering 2 tiles = 46.2857%Probability of covering 3 tiles = 8.8293%Probability of covering 4 tiles = 32.3135%Case 3:Probability of covering 1 tile  = 40.9600%Probability of covering 2 tiles = 46.0800%Probability of covering 3 tiles = 2.7812%Probability of covering 4 tiles = 10.1788%

Source

 

题意:

  就是问一个半径为r的硬币扔在r*c由t*t正方形组成的格子,

  问覆盖一个格子,两个格子,三个格子,四个格子的概率,要求圆心必须在矩形上

题解:

  发现1,2,3,4组成的概率为1,然后发现3这种情况最难计算,所以计算出1,2,4,然后1去减就可以了。

1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 8 const double PI=acos(-1.0),eps=1e-8; 9 10 int main()11 {12 int T,ca=0;13 for(scanf("%d",&T);T;T--)14 {15 double n,m,t,c,A[5];16 scanf("%lf%lf%lf%lf",&n,&m,&t,&c);17 A[0]=t*t*n*m;18 A[1]=(t-c)*(t-c)*n*m+(c*(t-c)+c*c/4.0)*4+c*(t-c)*(n+m-4);19 A[2]=2*c*(t-c)*n*m-c*(t-c)*(n+m)+c*c*(n+m-2);20 A[4]=PI*c*c/4*(n-1)*(m-1);21 A[3]=A[0]-A[1]-A[2]-A[4];22 printf("Case %d:\n",++ca);23 for(int i=1;i<=4;i++)24 printf("Probability of covering %d tile%s = %.4lf%%\n",i,(i==1)?" ":"s",A[i]/A[0]*100.0+eps);25 printf("\n");26 }27 }

 

转载于:https://www.cnblogs.com/fengzhiyuan/p/7747716.html

你可能感兴趣的文章
Mybatis逆向工程配置文件详细介绍(转)
查看>>
String类的深入学习与理解
查看>>
不把DB放进容器的理由
查看>>
OnePage收集
查看>>
Java parseInt()方法
查看>>
yahoo的30条优化规则
查看>>
[CCF2015.09]题解
查看>>
[NYIST15]括号匹配(二)(区间dp)
查看>>
json_value.cpp : fatal error C1083: 无法打开编译器生成的文件:No such file or directory
查看>>
洛谷 P1101 单词方阵
查看>>
Swift DispatchQueue
查看>>
C#和JAVA 访问修饰符
查看>>
小甲鱼OD学习第1讲
查看>>
HDU-1085 Holding Bin-Laden Captive-母函数
查看>>
php提示undefined index的几种解决方法
查看>>
LRJ
查看>>
Struts2环境搭建
查看>>
Linux: Check version info
查看>>
Javascript-正则表达式-开发中的使用.
查看>>
stl学习之测试stlen,cout等的运行速度
查看>>