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 }
     
  • 相关阅读:
    栈和其他寄存器大小
    checksec的安装及初步使用(新版)
    KMP算法之Next数组详解
    向上取整的三种方法
    C++STL(Standard Template Library,即标准模版库)——Map容器
    JS基础语法一
    JS函数学习
    JS对象学习(二)
    JavaStript对象学习(一)
    CSS3新特性学习(2)
  • 原文地址:https://www.cnblogs.com/gongpixin/p/6794505.html
Copyright © 2011-2022 走看看