2017hdu新生赛 1004 正品的概率

来源:互联网 发布:淘宝子账号 编辑:程序博客网 时间:2024/04/27 23:05

正品的概率

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1072    Accepted Submission(s): 125


Problem Description
袋中有m枚正品硬币,n枚次品硬币(次品硬币两面都有国徽),在袋中任取一枚,将它投掷k次,已知每次得到的都是国徽,那么这枚硬币是正品的概率是多少?
 

Input
输入包含多组数据,每组占一行包含3个正整m,n,k (1<=m,n,k<=50)。
 

Output
每组输出一行,包含一个最简分数,硬币为正品的概率。
 

Sample Input
1 1 1
 

Sample Output
1/3
 


公式是m/(m+n*(2^k))

include <iostream>#include <cstdio>using namespace std;long long gcd(long long a,long long b){    long long t;    while(b){        t=b;        b=a%b;        a=t;    }    return a;}long long pow_mod(int k){    long long y=2,t=1;    while(k){        if(k&1)t=t*y;        y=y*y;        k=k>>1;    }    return t;}int main() {    int m,n,k;    while (scanf("%d%d%d",&m,&n,&k)==3) {        long long a=m,b=m+n*pow_mod(k);        long long f=gcd(a, b);        a=a/f;        b=b/f;        printf("%lld/%lld\n",a,b);    }    // insert code here...    //std::cout << "Hello, World!\n";    return 0;}