HDU 5978 To begin or not to begin(水题)

来源:互联网 发布:网络棋牌违法吗 编辑:程序博客网 时间:2024/05/17 06:03

To begin or not to begin

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 63    Accepted Submission(s): 44


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.
 

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.
 

Sample Input
12
 

Sample Output
01
 

Source
2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
 

题意:盒子里有n个黑球和1个红球,每次不放回取球,谁先取到红球为胜利,问是先取还是后取的获胜概率大,或者概率相等。

思路:一开始还以为先取后取会影响概率,后来算了算发现不放回取球每次取到的概率是一样的,因此就直接看谁取的次数多即可。

#include <iostream>#include <string.h>#include <algorithm>#include <stdio.h>using namespace std;int main(){int n;while(~scanf("%d",&n)){n=n+1;if(n%2)puts("1");elseputs("0");}return 0;} 


0 0
原创粉丝点击