【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 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%

题目大意:有n*m块瓷砖,摆成一个大矩形。每块瓷砖是一个t*t的正方形

随意扔一个直径为d的圆盘,问能覆盖1/2/3/4个瓷砖的概率

其实就是问覆盖i个瓷砖情况的圆心可处在的面积和除上总面积

公式嘛……无脑推就好,注意下细节,然后就是加减乘除恶心点,还有记得都用double int*int可能会爆

代码如下:

#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#define LL long long
#define Pr pair<int,int>
#define fread() freopen("in.in","r",stdin)
#define fwrite() freopen("out.out","w",stdout)

using namespace std;
const int INF = 0x3f3f3f3f;
const int msz = 10000;
const int mod = 1e9+7;
const double eps = 1e-8;
const double PI = acos(-1.0);

int main()
{
	//fread();
	//fwrite();

	int t;
	double n,m,per,d,ans[4],sum;
	scanf("%d",&t);

	for(int z = 1; z <= t; ++z)
	{
		scanf("%lf%lf%lf%lf",&n,&m,&per,&d);

		if(z != 1) puts("");
		printf("Case %d:\n",z);
		sum = per*per*n*m;

		ans[0] = (per-d)*(per-d)*n*m+(per-d)*(d/2)*(n*2+m*2)+d*d;
		ans[0] /= sum;

		ans[1] = (per-d)*d*(m*(n-1)+n*(m-1))+d*d/2*((m-1)*2+(n-1)*2);
		ans[1] /= sum;

		ans[2] = (d*d-PI*d*d/4)*((m-1)*(n-1));
		ans[2] /= sum;

		ans[3] = PI*d*d/4*((m-1)*(n-1));
		ans[3] /= sum;

		printf("Probability of covering 1 tile  = %.4f%%\n",ans[0]*100);
		printf("Probability of covering 2 tiles = %.4f%%\n",ans[1]*100);
		printf("Probability of covering 3 tiles = %.4f%%\n",ans[2]*100);
		printf("Probability of covering 4 tiles = %.4f%%\n",ans[3]*100);
	}

	return 0;
}

时间: 2024-08-08 05:37:46

【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

[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

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

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 s

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,

poj 2249 Binomial Showdown(组合数 公式优化)

//  组合数学,开始了-- 题目地址 : poj 2249 Binomial Showdown Description In how many ways can you choose k elements out of n elements, not taking order into account? Write a program to compute this number. Input The input will contain one or more test cases. Eac

poj 3744 矩阵加速--概率DP

http://poj.org/problem?id=3744 犯二了,,递推式,矩阵幂什么都会,但是我推得跟别人不一样,,,应该是对矩阵理解问题,,,再看看 #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <iomanip> #include <cmath> #i

poj 2096 Collecting Bugs (概率dp 天数期望)

题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcomponent,问他找到所有的bugs和subcomponents的期望次数. 分析: 期望倒着推,概率正着推. dp[i][j]表示已经找到i种bug,并存在于j个子系统中,要达到目标状态的天数的期望.显然,dp[n][s]=0,因为已经达到目标了.而dp[0][0]就是我们要求的答案.dp[i][

POJ 3071:Football 概率DP

Football 题目链接: http://poj.org/problem?id=3071 题意: 有2^n支足球队在比赛,实行淘汰制,规则如下:第一轮  1与2比,3与4比...  第二轮  1.2中的胜者和3.4中的胜者比... 以此类推 直到第n轮决出winner,求最终胜利的球队编号. 题解: 设dp[i][j]为在第i轮中j号球队胜利的概率  转移方程:dp[i][j]=∑(dp[i-1][w]*dp[i-1][j]*p[j][w])   w为该轮可能与j球队比赛的球队,则该轮j胜w的