2020 CCPC Qinhuangdao Station Problem A. Greeting from Qinhuangdao
Title:
There are r red balloons and s blue balloons. Two balloons are randomly selected from these balloons. The probability that the two selected balloons are red balloons is expressed as a score. If the probability is 0, the output is 0/1
analysis:
This is a very friendly sign-in question,
which can be simplified by using the permutation and combination formula: be
careful not to forget the points
Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,r,b;
int x,y;
int temp;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
scanf("%d%d",&r,&b);
x=r*(r-1);//公式化简可得
y=(r+b)*(r+b-1);
temp=__gcd(x,y);//求最大公约数
x=x/temp;//分数化简
y=y/temp;
if(x==0)//输出
printf("Case #%d: 0/1\n",i+1);
else
printf("Case #%d: %d/%d\n",i+1,x,y);
}
return 0;
}