UVA10169 Urn-ball Probabilities数学计算+打表
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10169 Urn-ball Probabilities数学计算+打表相关的知识,希望对你有一定的参考价值。
Assume that you have two urns before you. Initially, one urn has one ball and the other urn has two balls and exactly one ball in each urn is red. At this initial stage you are asked to pick up two balls, one from each urn. Then one white ball is added in each urn and you are again asked to pick up one ball from each urn then again one white ball is added in each urn. This process continues for a certain time. Remember that you place the picked ball back to the urn after each pick up. You will have to determine the probability that in any of your pickups both of the picked balls were red and also the probability that all of your picked balls were red after certain steps.
Input
The input file contains several lines of inputs. Each line of the input file contains an unsigned integer N (N < 1000000) indicating how many times you will pick up. Of course after each pick up an increment in balls occurs as described previously.
Output
For each line of input print a single line of output containing a floating point number and an integer. The floating-point number indicates the probability that you have picked up two red balls in at least one of your pick-ups and the second integer denotes how many consecutive zeros are there after decimal point in the probability value that all of your pick ups has both balls as red.
Sample Input
1
2
20
Sample Output
0.500000 0
0.583333 1
0.688850 38
问题链接:UVA10169 Urn-ball Probabilities
问题简述:(略)
问题分析:数学计算问题,打表来提高速度,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10169 Urn-ball Probabilities */
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
double p[N + 1];
int cnt[N + 1];
void init()
{
double ans = 1;
p[0] = 1;
cnt[0] = 0;
for (long long i = 1; i <= N; i++) {
double t = 1.0 / (i * (i + 1));
ans *= t;
p[i] = (1 - t) * p[i - 1];
cnt[i] = cnt[i - 1];
while (ans < 1)
ans *= 10, cnt[i]++;
}
}
int main()
{
init();
int n;
while (scanf("%d", &n) == 1)
printf("%f %d\\n", 1 - p[n], cnt[n] - 1);
return 0;
}
以上是关于UVA10169 Urn-ball Probabilities数学计算+打表的主要内容,如果未能解决你的问题,请参考以下文章
通过vjudge刷Uva的题目(解决Uva网站打开慢的问题)