POJ3440--Coin Toss

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

3
5 5 10 3
7 4 25 20
10 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%
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define pi acos(-1.0)
int main()
{
	//freopen("in.txt","r",stdin);
	int t;
	scanf("%d",&t);
	for(int cas = 1;cas <= t;cas++)
	{
		double R,C,len,d;
		scanf("%lf%lf%lf%lf",&R,&C,&len,&d);
		double r = d/2.;
		double Ssum = 0,S1 = 0,S2 = 0,S3 = 0,S4 = 0;
		S1 += (len-d)*(len-d)*(R-2)*(C-2) + 4*(len-r)*(len-r) + (2*C + 2*R - 8)*(len - r)*(len - 2*r);
		S2 += r*(len - d)*4*(R-2)*(C-2) + (len - r)*r*8 + ((len - r)*r*2 + (len - d)*r)*(2*R + 2*C - 8);
		S3 += (4*r*r - pi*r*r)*(R-2)*(C-2) + (4*r*r - pi*r*r) + (2*r*r - pi*r*r/2)*(2*C + 2*R - 8);
		S4 += pi*r*r*(R-2)*(C-2) + pi*r*r + (pi*r*r/2)*(2*C + 2*R - 8);
		Ssum = R*C*len*len;
		S1 = S1>0?S1:0;	S2 = S2>0?S2:0;	S3 = S3>0?S3:0;	S4 = S4 > 0?S4:0;
		printf("Case %d:\n",cas);
		printf("Probability of covering 1 tile  = %.4lf%%\n",S1/Ssum*100);
		printf("Probability of covering 2 tiles = %.4lf%%\n",S2/Ssum*100);
		printf("Probability of covering 3 tiles = %.4lf%%\n",S3/Ssum*100);
		printf("Probability of covering 4 tiles = %.4lf%%\n",S4/Ssum*100);
		printf("\n");
	}
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值