uva 10169 - Urn-ball Probabilities !(概率)
题目链接: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;
}
uva 10169 - Urn-ball Probabilities !(概率)的更多相关文章
- UVa 10491 Cows and Cars (概率&广义三门问题 )
10491 - Cows and Cars Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- [uva 11762]Race to 1[概率DP]
引用自:http://hi.baidu.com/aekdycoin/item/be20a91bb6cc3213e3f986d3,有改动 题意: 已知D, 每次从[1,D] 内的所有素数中选择一个Ni, ...
- UVA 10828 - Back to Kernighan-Ritchie(概率+高斯消元)
UVA 10828 - Back to Kernighan-Ritchie 题目链接 题意:给图一个流程图,有结点的流程,每次进入下一个流程概率是均等的,有q次询问,求出每次询问结点的运行期望 思路: ...
- uva 11722 - Joining with Friend(概率)
题目连接:uva 11722 - Joining with Friend 题目大意:你和朋友乘火车,而且都会路过A市.给定两人可能到达A市的时段,火车会停w.问说两人能够见面的概率. 解题思路:y = ...
- UVA 11427 - Expect the Expected(概率递归预期)
UVA 11427 - Expect the Expected 题目链接 题意:玩一个游戏.赢的概率p,一个晚上能玩n盘,假设n盘都没赢到总赢的盘数比例大于等于p.以后都不再玩了,假设有到p就结束 思 ...
- uva 11427 - Expect the Expected(概率)
题目链接:uva 11427 - Expect the Expected 题目大意:你每天晚上都会玩纸牌,每天固定最多玩n盘,每盘胜利的概率为p,你是一个固执的人,每天一定要保证胜局的比例大于p才会结 ...
- UVA - 11427 Expect the Expected (概率dp)
Some mathematical background. This problem asks you to compute the expected value of a random variab ...
- UVa 1637 - Double Patience(概率DP)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 10529 - Dumb Bones(概率+区间dp)
UVA 10529 - Dumb Bones option=com_onlinejudge&Itemid=8&category=518&page=show_problem&am ...
随机推荐
- 黄聪:C#使用能够foreach对hashtable、List遍历时“集合已修改;可能无法执行枚举操作。”错误
解决办法:使用for循环,而不是foreach循环 例如: ArrayList akeys=new ArrayList(_transmit_tb.Keys); ;p> -;p--) { _tra ...
- (转)Flex开发工具Flex Builder 3 下载及注册码
本文转载自:http://blog.csdn.net/wlxtaking/article/details/5779762 Flex是通过java或者.net等非Flash途径,解释.mxml文件组织c ...
- [LigerUI]使用记录
1. 下拉框设定 鼠标移开隐藏 但想改变下拉框大小时 很难一次定位到下拉框右下角那个点 2. ligerTab 自带标题菜单 但想修改成类似于 chrome 的标题菜单时 貌似没有找到方法 我用 ea ...
- 折腾一天,获取下列多选框的所有选中值,原生js可直接通过obj.val()来获取,可jq不行,要通过循环取值来获取;
折腾一天,获取下列多选框的所有选中值,原生js可直接通过obj.val()来获取,可jq不行,要通过循环取值来获取;
- 双系统(Windows+Ubuntu)重装Ubuntu后,修复引导
重装Ubuntu后,重启机器,Windows系统消失了.进入BIOS修改启动顺序,Windows系统恢复了,但是,刚装好的Ubuntu没了,一开机,电脑自动进入Windows. 解决办法: 用装系统的 ...
- 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #10 Fair Group Scheduling
HACK #10 Fair Group Scheduling 本节介绍Cgroup之一.管理CPU资源的Fair Group Scheduling.Fair Group SchedulingFair ...
- mysql-5.6.20主从同步错误之Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND
mysql-5.6.20主从同步错误之Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND 方法一: 1.Error_code: 1032; ha ...
- 常用工具&网址
工具 I tell you http://www.win7999.com/news/197912345.html VisualSVN Server(免费) http://www.visualsvn.c ...
- Apache Kylin本地启动
首先:kylin是一种Online Analytics Platform. kylin 在Apache的首页是http://kylin.apache.org/cn/. kylin git代 ...
- leetcode219
public class Solution { Dictionary<int, List<int>> dic = new Dictionary<int, List< ...