HDU 5978 To begin or not to begin(概率)
来源:互联网 发布:淘宝装修店铺视频教程 编辑:程序博客网 时间:2024/05/01 23:08
To begin or not to begin
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 558 Accepted Submission(s): 370
Problem Description
A box contains black balls and a single red ball. Alice and Bob draw balls from this box without replacement, alternating after each draws until the red ball is drawn. The game is won by the player who happens to draw the single red ball. Bob is a gentleman and offers Alice the choice of whether she wants to start or not. Alice has a hunch that she might be better off if she starts; after all, she might succeed in the first draw. On the other hand, if her first draw yields a black ball, then Bob’s chances to draw the red ball in his first draw are increased, because then one black ball is already removed from the box. How should Alice decide in order to maximize her probability of winning? Help Alice with decision.
Input
Multiple test cases (number of test cases≤50), process till end of input.
For each case, a positive integer k (1≤k≤10^5) is given on a single line.
For each case, a positive integer k (1≤k≤10^5) is given on a single line.
Output
For each case, output:
1, if the player who starts drawing has an advantage
2, if the player who starts drawing has a disadvantage
0, if Alice's and Bob's chances are equal, no matter who starts drawing
on a single line.
1, if the player who starts drawing has an advantage
2, if the player who starts drawing has a disadvantage
0, if Alice's and Bob's chances are equal, no matter who starts drawing
on a single line.
Sample Input
12
Sample Output
01
Source
2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
Recommend
wange2014 | We have carefully selected several similar problems for you: 6018 6017 6016 6015 6014
一开始我是想要通过条件概率计算,即第一次抽中红球的概率是1/3、第二次是(1-1/3)*1/2、在算三次的时候就懵了,如果通过条件概率进行计算的话应该是前两个事件不发生的条件下第三次抽中即(1-1/3-1/3)*1这样。这个算法是可行的A了,然后进一步,如果不用条件概率,单独考虑在第i次抽到红球的概率 就会发现每次抽到的概率其实是一样的都是1/n,所以进一步,如果k+1是基数的话,那么先手取球的总概率就会大,偶数的话就是一样的,此外这道题还在浮点数处理的地方卡了一下,注意,判断两个浮点数的大小关系的时候,需要先判断两数是否相等的情况,再判断大小关系。
0 0
- HDU 5978 To begin or not to begin(概率)
- HDU 5978 To begin or not to begin(概率)
- HDU 5978 To begin or not to begin (概率数学)
- hdu 5978 · To begin or not to begin【概率题】【手速题】
- hdu 5978 To begin or not to begin(概率期望)
- HDU 5978 icpc 大连 To begin or not to begin
- hdu 5978 To begin or not to begin
- HDU 5978 To begin or not to begin(水题)
- hdu 5978 To begin or not to begin
- HDU5978 To begin or not to begin(概率+规律)
- HDU5971 To begin or not to begin
- hdoj 5978 To begin or not to begin
- HDU 5978 To begin or not to begin (简单博弈--找规律)
- HDU 5978 && 2016ICPC大连 H: To begin or not to begin
- ICPC 2016 DALIAN H To begin or not to begin
- To Begin
- perl---use lib or BEGIN{ } to add directory to @INC
- Begin to sell
- inverse和cascade的区别,以及一对多添加操作时外键为Null的问题
- RPL(12):RFC6550翻译(12)---目标函数准则
- <操作系统:精髓与设计原理> 进程描述和控制
- 1065
- PAT-B 1040. 有几个PAT(25)
- HDU 5978 To begin or not to begin(概率)
- Vue.js学习系列(三十二)-- Vue.js样式绑定(三)
- 大数据工程师(开发)面试系列(5)
- maven SpringMVC,Spring,Mybatis整合
- BZOJ 2002 分块
- 23种设计模式分析(1):创建型模式
- TypeLite(二)-- 编写生成器
- 第三章 字符串、向量和数组(重点)
- 【Java集合源码剖析】LinkedHashmap源码剖析