题目链接:传送门
思路:注意是比较人第一天女装的概率和连续两天女装的概率
Ans=P(两次都取到女装P1)/P(第一次取到女装P2)
P1=x*(x-1)/n*(n-1)+y*(y-1)/m*(m-1)
P2=x/n+y/m;
然后化简,注意四舍五入
代码:
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; LL gcd(LL a,LL b) { return b==0?a:gcd(b,a%b); } int main(void) { LL m,n,x,y,z; while(~scanf("%lld%lld%lld%lld%lld",&n,&m,&x,&y,&z)) { LL up,down,vv; up=x*(x-1)*m*(m-1)+y*(y-1)*n*(n-1); down=(n-1)*(m-1)*(x*m+y*n); if(z==1) { if(up==0) printf("0/1 "); else if(up==down) printf("1/1 "); else { vv=gcd(up,down); printf("%lld/%lld ",up/vv,down/vv); } } else { if(up==0) printf("0.000 "); else if(up==down) printf("1.000 "); else { double ans=(1000.0*up)/(1.0*down); up=(LL)(ans+0.5); ans=1.0*up/1000.0; printf("%.3lf ",ans); } } } return 0; }