UVa 10056 What is the Probability ? (概率&有一个陷阱)

What is the Probability 当一个玩家掷骰子时,如果某个预定情况发生(比如骰子显示3的一面朝上,绿色的一面朝上,等等),他就赢了。因此,先是第一个玩家掷骰子,然后第二个掷骰子,最后是第n个玩家掷骰子,再接下来,下一轮,先第一个玩家掷骰子,以此类推。然后给出一个浮点数字p,表示单次掷骰子时成功事件发生的概率(如果成功事件是骰子显示3的一面朝上,则p是单次掷骰子时显示3的一面朝上的概率)。对于普通骰子,显示3的一面朝上的的概率是1/6);最后给出一个i(i≤n),表示要确定其获胜概率的玩家的序列号(序列号从1到n)。 阅读详情

10056 - What is the Probability ?

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=997

Probability has always been an integrated part of computer algorithms. Where the deterministic algorithms have failed to solve a problem in short time, probabilistic algorithms have come to the rescue. In this problem we are not dealing with any probabilistic algorithm. We will just try to determine the winning probability of a certain player.

 

A game is played by throwing a dice like thing (it should not be assumed that it has six sides like an ordinary dice). If a certain event occurs when a player throws the dice (such as getting a 3, getting green side on top or whatever) he is declared the winner. There can be N such player. So the first player will throw the dice, then the second and at last the N th player and again the first player and so on. When a player gets the desired event he or she is declared winner and playing stops. You will have to determine the winning probability of one (The I th) of these players.


Input

Input will contain an integer S (S<=1000) at first, which indicates how many sets of inputs are there. The next S lines will contain S sets of inputs. Each line contain an integer N (N<=1000) which denotes the number players, a floating point number p which indicates the probability of the happening of a successful event in a single throw (If success means getting 3 then p is the probability of getting 3 in a single throw. For a normal dice the probability of getting 3 is 1/6), and I (I<=N) the serial of the player whose winning probability is to be determined (Serial no varies from 1 to N). You can assume that no invalid probability (p) value will be given as input.


Output

For each set of input, output in a single line the probability of the I th player to win. The output floating point number will always have four digits after the decimal point as shown in the sample output.

 

Sample Input:

2
2 0.166666 1
2 0.166666 2

 

Sample Output:

0.5455

0.4545


注意p=0时分母会为0,要特判。


完整代码:

/*0.016s*/

#include<cstdio>
#include<cmath>

int main()
{
	int t, n, i;
	double p;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%lf%d", &n, &p, &i);
		printf("%.4f\n", p == 0 ? p : p * pow(1 - p, i - 1) / (1 - pow(1 - p, n)));
	}
	return 0;
}


区域法(zonal method)重构波前 目的:实现区域法的Matlab代码 1.理论介绍 区域法波前重构即从波前探测器测得的波前斜率中恢复出波前的相位值,其分为:休晋模型(Hudgin)[90]、绍契威尔模型(Southwell)[40]和弗雷德模型(Fried)[48]。 1.1 Fried模型,对于N×N微透镜阵列构成的网格: 以3*3的子透镜为例,解释上式,对其展开 改写为矩阵形式: 记作:S=AΦ,A根据N而确定。S是波前探测器测得的斜率,Φ是重构矩阵的相位值。 1.2 而Southwel... 阅读详情

相关推荐

《AFSim 2.9中文参考手册》

本栏目将对《AFSim 2.9中文参考手册》进行持续更新,欢迎关注交流!对本文或者AFSIM相关内容感兴趣的朋友,可私心联系作者。《AFSim 2.9中文参考手册》内容概览。

henggesim的博客 1万+

UVA10056 What is the Probability【概率】

Probability has always been an integrated part of computer algorithms. Where the deterministic algorithms have failed to solve a problem in short time, probabilistic algorithms have come to the rescue. In this problem we are not dealing with any probabilis

海岛Blog 595

基于SpringBoot+Vue的公司考勤管理系统

为什么选择我博主是CSDN毕设辅导博客第一人兼开派祖师爷、博主本身从事开发软件开发、有丰富的编程能力和水平。专注于Java技术领域和学生毕业项目实战,高校老师/讲师/同行前辈交流和合作。

m0_71849512的博客 1165

UVA10056 - What is the Probability ?(概率)

UVA10056 - What is the Probability ?(概率) 题目链接 题目大意:有n个人玩游戏,一直到一个人胜出之后游戏就可以结束,要不然就一直从第1个到第n个循环进行,没人一轮,给出每个人胜出的概率为p,问第i个人胜利的概率。 解题思路:第i个人要胜利,那么就可能在第一轮胜利,也可能在第i轮胜利,那么胜利的概率就是q = 1 - p;概率 = q^(i -

1652

2025最新正版Autodesk 3ds Max 2022安装教程:从下载到中文环境配置全流程解析

Autodesk 3ds Max 2022是一款专业的三维建模、动画和渲染软件,广泛应用于影视制作、游戏开发、建筑可视化等领域。

waicsdn_haha的博客 1万+

解密m3u8视频合并:从猫抓插件到本地文件修改全流程

本文详细解析了m3u8视频合并的全流程,特别针对加密视频片段提供了解决方案。从使用猫抓插件捕获m3u8文件地址,到利用N_m3u8DL-CLI工具自动下载、解密并合并ts片段,手把手教你处理AES-128加密等常见问题,最终生成完整的本地MP4文件,适合需要备份或处理流媒体资源的用户。

weixin_29290947的博客 1380

uva 10056 What is the Probability ? 概率是多少

uva 10056

@fei 1029

使用everything出现mem_virtual_alloc(): Fatal Error: out of memory解决方案

本文主要介绍了使用everything出现mem_virtual_alloc(): Fatal Error: out of memory解决方案,希望能对使用everything的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 1万+

uva 10056 - What is the Probability ?(概率)

题目连接:uva 10056 - What is the Probability ? 题目大意:给出n和p以及m,表示有n个人在丢色子, 谁先丢到某个值就表示胜利,每个人丢到的胜利数值的概率都为p,问第m个人获胜概率。 解题思路:因为n个人可以轮流丢色子,所以要自己定一个下限,而且以为人数比较多,每次并不需要将m以外的人都考虑进去,可以默认为没有丢到胜利的数值。 #inclu...

445822357 263

Codex 100个真实案例 - 用AI做英语单词计划学习工具(记忆曲线+测验)

背单词是英语学习的基本功,但市面上的背单词 APP 要么收费、要么广告太多。本案例用 Codex 从零打造一个 **英语单词计划学习工具**,实现 SM-2 间隔重复算法(Anki 的核心算法)、单词本增删改查、多种测验模式(选择题/拼写/听写)、TTS 发音播放,以及学习数据的可视化统计图表。全程用自然语言驱动 Codex,用 Python 写后端逻辑 + 终端 UI,打造你的私人背单词助手!

yueyeguzhuo的专栏 225

19 04-读取DTC快照信息

为了方便找到故障的原因,车厂一般会在诊断调查表中定义一些信息作为快照信息,例如故障发生时间、电压、行驶里程数、车速等。在对应故障发生时,ECU端要记录发生故障时的快照信息,客户端可以通过此服务检索客户端定义的DTCMaskRecord的捕获DTC Snapshot记录号以及DTCSnapshot记录数据。通过查找故障发生时刻的这些数据,来分析故障原因。

诊断协议那些事儿's blog 5158

2021-01-20 灵动ICPC集训

2021-01-20 灵动ICPC寒假集训 学习内容:几何初步、欧几里得、概率论微积分初步、矩阵计算、数学初步 1.Birthday Cake 试题来源:Randy Game - Programming Contest 2001A 源代码 2.Is This Integration ? 试题来源:Math &amp; Number Theory Lovers’ Contest 2001 源代码 3. Simple division 试题来源:November 2002 Monthly Contest 源代码

m0_51562272的博客 570

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

c语言算法的学习(数学算法,欧几,概率论)

contextA Birthday Cake问题重述:输入输出试题解析源代码B Is This Integration ?问题重述输入输出Sample InputSample Output问题解析试题解析源代码C Simple division问题重述输入输出Sample InputSample Output问题解析源代码E Dead Fraction问题重述输入输出E Euclid Problem问题重述F What is the Probability ?G BurgerH Coin Toss A Bi

seekerzhz的博客 815

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

2021-01-20

灵动ICPC冬令营基础-3 A - Birthday Cake Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them. Now we put the cake onto a Descartes coordinate. Its center is at (0, 0), and the cake’s length of radius is 100. There are 2N (N is a i

qq_51646445的博客 360

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

数学题(概率)UVA 10056-What is the Probability ?

数学题(概率)UVA 10056-What is the Probability ? 题目链接: F - What is the Probability ? 思路: 题目情景是有N个人,每个人获得想要得的数字的概率都是p,轮流抽,当有一个人获得想要的数字时,游戏结束,问第 I 个人获胜的概率 其实就是一个转圈抽奖的问题,设N个人都抽一次为一轮,那么第I个人在 K轮获胜的...

[SZU_Crayon] 553

10056 - What is the Probability ? 解题报告

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=997 N个人轮流掷筛子,赢的概率为P,求第i个人赢的概率是多少。 可以求出第i个人赢的概率为P(1-P)^(i-1) * [1 + (1-P)^N + (1-P)^2N + ...]

zjwoody的专栏 1297

UVA - 10056 What is the Probability ?

题目大意:有n个人玩丢骰子游戏,丢到某个点数为赢然后结束,从第1个人开始丢然后依次下去到n,重新从1开始,直到有人赢为止。 输入n个人,每个人丢到目标点数的概率p,第m个人。求第m个人赢的概率 解题思路: 我们直接求出第一个人第100轮赢的概率,然后推出第m个人赢的概率 #include #include int main() { int T; scanf("%d",

Bingo 1810

What is the Probability - UVa 10056 概率

题意:从1-n轮回掷骰子,每个人每次有p的概率赢,问第m个人赢的概率。 思路:设其为ans,ans=P(前m-1人个都没中)*p+P(n个人都没中)*ans。            整理后为ans=p*pow(q,m-1)/(1-pow(q,n)); q=1-p。 AC代码如下: #include #include #include using namespace std; int T,t

提比的强行AC 636

UVA - 10056 What is the Probability ?(概率)

题意: 有n个人玩丢骰子游戏,丢到某个点数为赢然后结束,从第1个人开始丢然后依次下去到n,重新从1开始,直到有人赢为止。 输入n个人,每个人丢到目标点数的概率p,第m个人。求第m个人赢的概率。 解析: 如果我要想第m个人赢,可以看得出来那必须前面所有的人没中, 那么前面所有的人没赢的概率是 (1-p)^前面的人的人数 然后我第m个人必须赢,则所有的最终概率是(1-p)^前

小G的ACM之路 723

matlab验证对称三相电路,不对称三相电路中,中线的电流为()。 A.0 B. C. D....

不对称三相电路中,中线的电流为()。 A.0 B. C. D.更多相关问题【单选题】目前可编程器件通用的硬件描述语言有哪两种?A. 汇编语言和C B. VHDL和Verilog C. C和Verilog D. Python 和Verilog【单选题】以下选项中,不属于软件需求分析阶段主要工作的是() (10.0分)A. 需求分析 B. 需求评审 C. 需求获取 D. 需求变更申请【单选题】以下选项...

weixin_34083807的博客 1189

10056 - What is the Probability ?

/* 简单概率题,一次AC */ #include int main() { //freopen("f://data.in", "r", stdin); int T; scanf("%d", &T); while(T--) { int N, I; double p; scanf("%d %lf %d", &N, &p, &I); double q, t; int i

700

HDU 4254 A Famous Game (概率&组合数学公式)

x

AC,∑ndless 2391

UVa 10491 Cows and Cars (概率&广义三门问题 )

【历史介绍】 三门问题(Monty Hall problem)亦称为蒙提霍尔问题、蒙特霍问题或蒙提霍尔悖论,大致出自美国的电视游戏节目Let's Make a Deal。问题名字来自该节目的主持人蒙提·霍尔(Monty Hall)。参赛者会看见三扇关闭了的门,其中一扇的后面有一辆汽车,选中后面有车的那扇门可赢得该汽车,另外两扇门后面则各藏有一只山羊。当参赛者选定了一扇门,但未去开启它的时候,节目主持人开启剩下两扇门的其中一扇,露出其中一只山羊。主持人其后会问参赛者要不要换另一扇仍然关上的门。问题是:换另一扇

AC,∑ndless 2059
上一篇: UVa 10344 23 out of 5 (全排列枚举&回溯)
下一篇: UVa 412 Pi (简单gcd)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值