A Greeting from Qinhuangdao 概率

题意:$r$个红球,$b$个蓝球,不放回摸两次均为红球的概率。

思路:基础概率论,注意一下概率为0的情况和分子分母的约分。

代码:

 1 #include <bits/stdc++.h>
 2 
 3 #define debug(...)  fprintf(stderr,__VA_ARGS__)
 4 #define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
 5 #define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
 6 #define rep(i,x,y) for(int i=(x);i<=(y);++i)
 7 #define _max(a,b) (a)>(b)? (a):(b)
 8 #define _min(a,b) (a)<(b)? (a):(b)
 9 
10 using namespace std;
11 typedef long long ll;
12 typedef unsigned long long ull;
13 typedef pair<int,int> pii;
14 typedef pair<ll,int> pli;
15 typedef pair<int,ll> pil;
16 typedef pair<ll,ll> pll;
17 
18 int t;
19 int r,b;
20 int main(){
21     cin>>t;
22     for(int cs=1;cs<=t;++cs){
23         cin>>r>>b;
24         if(r<=1){
25             printf("Case #%d: 0/1\n",cs);
26             continue;
27         }else{
28             int fz=r*(r-1),fm=(r+b)*(r+b-1),re=__gcd(fz,fm);
29             printf("Case #%d: %d/%d\n",cs,fz/re,fm/re);
30         }
31     }
32     return 0;
33 }
View Code

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2021-10-27
  • 2022-12-23
  • 2021-11-24
  • 2022-01-13
  • 2021-12-20
  • 2021-12-21
猜你喜欢
  • 2022-12-23
  • 2022-01-26
  • 2021-11-05
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
相关资源
相似解决方案