Gambling
Accepted : 27 Submit : 113
Time Limit : 2000 MS Memory Limit : 65536 KB
Gambling
In ICPCCamp, gambling is conducted as follow. A player will draw balls from an opaque bag containing a red balls, b green balls and c blue balls initially. Balls in the bag will be drawn in equal probability while drawn balls won’t be put back into the bag. The player continues the process until he collects all a red balls, or all b green balls, or all c blue balls. He ends up with First Prize if he collects a red balls, or Second Prize if he collects b green balls, or Third Prize otherwise.
Bobo is going to take part in the above gambling. Therefore, it is very important for him to work out the probability of winning each prize.
Input
The input contains at most 40 sets. For each set:
Three integers a,b,c (1≤a,b,c≤103).
Output
For each set, three irreducible fractions pA,pB,pC denote the probability of winning First Price, Second Price, and Third Price, respectively.
Sample Input
1 1 1
1 2 3
Sample Output
1/3 1/3 1/3
7/12 4/15 3/20
三种颜色球,分别数量为a,b,c,从一个口袋里无放回的选,求获取冠军,亚军,季军的概率。
选中a个红球则冠军,选中B个绿球,则亚军,c个黄球季军
反过来逆向思维想,想要求红球概率,假设选中了最后一个球是黄球,那么概率为c/(a+b+c) ,前一个为绿球则为剩下的a+c中选取c 概率为c/(a+b);
所以最后一个为绿球概率为b/(a+b+c) * c/(a+c);
还有可能最后一个为黄球,有上推出概率为 c/(a+b+c) *b/(a+b);
然后求获取亚军概率
{
最后一个为 红球 a/(a+b+c) * c/(b+c);
最后一个为 黄球 c/(a+b+c) * c/(a+b);
}
再求季军
{
最后一个为 红球 a/(a+b+c) * b/(b+c);
最后一个为 绿球 b/(a+b+c) * a/(a+c);
}
最后附上代码:
注意开long long
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#define INF 0x3f3f3f
using namespace std;
long long gcd(long long x,long long y)
{
if(x<y)
return gcd(y,x);
else if(y==0)
return x;
else return gcd(x-y,y);
}
long long cal(long long R1,long long R2,long long Y1,long long Y2)
{
long long s1=R1/gcd(R1,R2);
long long s2=R2/gcd(R1,R2);
long long s3=Y1/gcd(Y1,Y2);
long long s4=Y2/gcd(Y1,Y2);
long long RRFZ=s1*s4+s3*s2;
long long RRFM=s2*s4;
printf("%I64d/%I64d",RRFZ/gcd(RRFZ,RRFM),RRFM/gcd(RRFZ,RRFM));
}
int main()
{
long long a,b,c;
long long s1,s2;
//cout<<gcd(3,5);
while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
{
long long R1=b*c;
long long R2=(a+b+c)*(a+c);
long long Y1=b*c;
long long Y2=(a+b+c)*(a+b);
cal(R1,R2,Y1,Y2);
cout<<' ';
long long R11=a*c;
long long R22=(a+b+c)*(b+c);
long long Y11=a*c;
long long Y22=(a+b+c)*(a+b);
cal(R11,R22,Y11,Y22);
cout<<' ';
long long R111=a*b;
long long R222=(a+b+c)*(b+c);
long long Y111=a*b;
long long Y222=(a+b+c)*(a+c);
cal(R111,R222,Y111,Y222);
cout<<endl;
//int
}
return 0;
}