首页 > 学院 > 开发设计 > 正文

HDU 5978 To begin or not to begin (简单博弈--找规律)

2019-11-10 16:55:14
字体:
来源:转载
供稿:网友

大体题意:

给你k 个黑球和1个红球,两个轮流抽,抽到红球算赢,问先手赢的概率大还是后手大,还是概率相等?

思路:

写几个小的数手算一下 就看到规律了。

如果k 是偶数的话,那么先手的概率是 ((n+2)/3)/(n+1)  大于后手的概率 输出1

如果k 是奇数的话,那么先手后手概率都是1/2.

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){	int n;	while(~scanf("%d",&n)){		if (n & 1) puts("0");		else puts("1");	}	return 0;}

To begin or not to begin

Time Limit: 2000/1000 MS (java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 476    Accepted Submission(s): 316PRoblem DescriptionA 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. InputMultiple 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. OutputFor each case, output:1, if the player who starts drawing has an advantage2, if the player who starts drawing has a disadvantage0, if Alice's and Bob's chances are equal, no matter who starts drawingon a single line. Sample Input
12 Sample Output
01 Source2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学) Recommendwange2014   |   We have carefully selected several similar problems for you:  6014 6013 6012 6011 6010  


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表