zoukankan      html  css  js  c++  java
  • hdu 5978 To begin or not to begin(概率,找规律)

    To begin or not to begin

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


    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
     
     
     

    给出 n 个黑球,一个红球。

    抽出红球胜利。如果先手有优势 输出 1 没有优势 输出 2 机会均等输出 0

    思路:可以手算出前几项的概率。

    胆大的现在就可以猜答案了。奇数0 偶数 1  

    不放心的话,就打个表。

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<math.h>
     4 #include <string>
     5 #include<string.h>
     6 #include<map>
     7 #include<queue>
     8 #include<set>
     9 #include<utility>
    10 #include<vector>
    11 #include<algorithm>
    12 #include<stdlib.h>
    13 using namespace std;
    14 #define maxn 200100
    15 #define maxm 200005
    16 #define rd(x) scanf("%d", &x)
    17 #define rd2(x, y) scanf("%d%d", &x, &y)
    18 #define mod 1000000007
    19 
    20 int main()
    21 {
    22     int k;
    23     while(~scanf("%d", &k)){
    24         if(k%2) printf("0
    ");
    25         else printf("1
    ");
    26     }
    27     return 0;
    28 }
     
  • 相关阅读:
    iOS 11和xcode9
    #ifdef __OBJC__宏定义的作用
    项目小分析------从 优普钱包工资单 谈代码的规范性和界面的一般写法
    UIAlertView 点击按钮后控制其是否消失
    iOS 限制输入字数完美解决方案
    tn文本分析语言(四) 实现自然语言计算器
    重磅开源:TN文本分析语言
    差一点其实差很多
    光棍节之夜,用数据分析帮女神学姐选婚房
    你能排第几?2016互联网行业薪酬数据分析
  • 原文地址:https://www.cnblogs.com/gongpixin/p/6794505.html
Copyright © 2011-2022 走看看