zoukankan      html  css  js  c++  java
  • hdu 5194 DZY Loves Balls

    Problem Description
    There are n black balls and m white balls in the big box.
    Now, DZY starts to randomly pick out the balls one by one. It forms a sequence S. If at the i-th operation, DZY takes out the black ball, Si=1, otherwise Si=0.
    DZY wants to know the expected times that '01' occurs in S.
     
    Input
    The input consists several test cases. (TestCase150)
    The first line contains two integers, n, m(1n,m12)
     
    Output
    For each case, output the corresponding result, the format is p/q(p and q are coprime)
     
    Sample Input
    1 1 2 3
     
    Sample Output
    1/2 6/5
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int m,n;
     6 void build(int x,int y,int t1,int t2,int &ans1,int &ans2)
     7 {
     8     int a,b;
     9     if (t2==m) {ans1=1;ans2=1;return ;}
    10     if (t1==n)
    11     {
    12         if (x==0) ans2=1;
    13         else ans2=0;
    14         ans1=1;
    15         return ;
    16     }
    17     build(y,0,t1,t2+1,ans1,ans2);
    18     a=ans1;
    19     b=ans2;
    20     build(y,1,t1+1,t2,ans1,ans2);
    21     a+=ans1;
    22     b+=ans2;
    23     if (x==0&&y==1) b+=a;
    24     ans1=a;
    25     ans2=b;
    26 }
    27 int main()
    28 {
    29     int a,b,c,ans1,ans2;
    30     while (~scanf("%d%d",&n,&m))
    31     {
    32         build(-1,0,0,1,ans1,ans2);
    33         a=ans1;b=ans2;
    34         build(-1,1,1,0,ans1,ans2);
    35         a+=ans1;b+=ans2;
    36         n=b;
    37         m=a;
    38         a=max(n,m);
    39         b=min(n,m);
    40         c=1;
    41         while (c)
    42         {
    43             c=a%b;
    44             a=b;
    45             b=c;
    46         }
    47         printf("%d/%d
    ",n/a,m/a);
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    如何在Linux下的C++文件使用GDB调试
    21天学通C++(C++程序的组成部分)
    嵌入式Linux应用程序开发
    项目部署的问题
    未解决
    报错
    随笔
    逆向工程出现的错误1
    jpa学习
    springmvc整合mybaits
  • 原文地址:https://www.cnblogs.com/pblr/p/4728291.html
Copyright © 2011-2022 走看看