题目链接:uva 10169 - Urn-ball Probabilities !
题目大意:在一个箱子中,原本有1个红球,然后任意取出(有放回)一个球,然后再往里放一个白球(每次取都要放进一个白球),给出n,表示取了n次球,要求输出至少有连续抽到两个红球的概率,以及没有连续抽到红球的概率,因为没有连续抽到红球的概率非常小,所以输出小数点后有几位为0.
解题思路:将每两次去球作为一次讨论,p = 1/(i * (i + 1),然后每次叠乘(1 - p)就可以得到q, (1 - q)为第一个答案。然后每次叠乘p得到ans,计算ans小数点后的0的个数,即为第二个答案。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
const int N = 1000005;
double q[N];
int cnt[N];
void init() {
double p = 1, ans = 1;
q[0] = 1;
cnt[0] = 0;
for (long long i = 1; i < N; i++) {
p = 1./(i * i + i);
q[i] = (1 - p) * q[i - 1];
ans *= p;
cnt[i] = cnt[i - 1];
while (floor(ans) < 1e-10) {
cnt[i]++;
ans *= 10;
}
}
}
int main () {
int n;
init();
while (scanf("%d", &n) == 1) {
printf("%.6lf %d\n", 1 - q[n], cnt[n] - 1);
}
return 0;
}
分享到:
相关推荐
基于多条件查询语句概率的数据库内部攻击监控系统 这是一个基于多条件查询语句概率的数据库内部攻击监控系统的实现,这是我硕士学位的一个顶点项目。 如果你想知道这个项目是关于什么的: :
Chapter9 - Intro to Activation Functions - Modeling Probabilities(1).ipynb
refresher-probabilities-statistics
refresher-probabilities-statistics.pdf
Bayes, Boltzmann and Bohm - Probabilities in Physics Bayes, Boltzmann and Bohm - Probabilities in Physics Bayes, Boltzmann and Bohm - Probabilities in Physics
predicted_probabilities
Grenander - Probabilities on Algebraic Structures.pdf
scEpath是一种新颖的计算方法,用于定量测量单细胞的发育能力和可塑性以及细胞状态之间的转移概率,并从单细胞基因表达数据推断谱系关系和伪时间顺序。 此外,scEpath还可以进行许多下游分析,包括针对给定的细胞簇...
An expanded double-quantitative model regarding probabilities and grades and its hierarchical double-quantitative attribute reduction
Forex Patterns and Probabilities
n-gram概率使用NLTK库生成的Unigram和Bigram令牌。 计算的Unigram和Bigram概率。 并显示前15个常用词。
A novel abstraction-guided simulation approach using posterior probabilities for verification
Chapter 2 Probabilities: Bayesian Classifiers Chapter 3 Similarities: Nearest-Neighbor Classifiers Chapter 4 Inter-Class Boundaries: Linear and Polynomial Classifiers Chapter 5 Artificial Neural ...
双Cox风险模型破产概率指数与非指数上界,刘艳,,本文考虑了保费收入过程和索赔过程都基于Cox 过程的保险风险模型。应用鞅方法,本文给出了该保险风险模型的破产概率的指数上界,�
对自适应操作概率遗传算法有详细的介绍,有很好的参考价值!
Chapter 2 Probabilities: Bayesian Classifiers Chapter 3 Similarities: Nearest-Neighbor Classifiers Chapter 4 Inter-Class Boundaries: Linear And Polynomial Classifiers Chapter 5 Artificial Neural ...
D10-WoD-概率该代码的目的是在您使用World of Darkness角色扮演系统掷骰子时获得成功的可能性。 简要提醒一下WoD系统: 掷出与属性+技能中的角色得分一样多的D10(带有10个面的骰子)(例如:您想挥剑,您的力量为3...
榆树概率 Elm-lang中的概率分布和绘图。 基于图层的函数,积分和导数图(受Hadley Wickham的ggplot2启发,但范围更窄) 离散的 二项式 超几何 泊松 连续的 制服 普通+标准普通 指数的 以及一些辅助功能,包括: ...
probabilities are represented by conditional log-normal distributions. The user can: 1. Define the number of states of the model 2. Set if the state sequence reconstruction considers the ...