2016 ICPC大连赛区 hdu5978 To begin or not to begin

13 篇文章 0 订阅


To begin or not to begin

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


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
  
  
1 2
 

Sample Output
  
  
0 1
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5981  5979  5977  5976  5975 
 
题意:给k个黑球,1个红球,谁先拿到红球谁就赢,问先手赢的几率大还是后手赢的几率大或者一样大。

思路:这是个简单的概率问题,第n回合抽到红球的几率一定等于1/(k+1),那么赢的几率=拥有的回合数*(1/(k+1)),如果k为奇数,那么两边回合一样所以几率一样大,如果k为偶数那么必定先手的有多一个回合的机会,所以几率更大,下面给代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
typedef long long LL;
using namespace std;
#define maxn 1005
#define ll l,mid,now<<1
#define rr mid+1,r,now<<1|1
#define lson l1,mid,l2,r2,now<<1
#define rson mid+1,r1,l2,r2,now<<1|1
int main(){
    int k;
    while(~scanf("%d",&k)){
        if(k&1)
            printf("0\n");
        else
            printf("1\n");
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值