NYOJ926(概率)

时间:2023-12-23 09:15:20

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=926

设最终A获胜的概率为P,则B获胜的概率为1-P;

因此我们只需要考虑A获胜的概率即可;

又由题意可知每一轮中他们做对题目的概率是不变的;

可分两种情况讨论:一是在当前局中A获胜了,用p1表示,则p1=(a%)*(1-b%);

或者当前局为平局,用p2表示其概率,则p2=(a%)*(b%),即A只能在之后的游戏中获胜,当前局轮白了,对之后的胜负没有影响,即A此时的胜率仍然为P;

由此可得:p=p1+p2*p;即p=p1/(1-p2);带入p1,p2可得:p=(100*a-a*b)/(10000-a*b);

ac代码:

 #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <set>
#include <map>
#define mod 1000000007
#define MAXN 100000+10
#define INF 1000000000
#define eps 10e-6
#define ll long long
using namespace std; bool cmp(int a, int b)
{
return a > b;
} //****************************************************************************** int main(void)
{
std::ios::sync_with_stdio(false), cin.tie(), cout.tie();
int t;
cin >> t;
while(t--)
{
int a, b;
cin >> a >> b;
int x=*a-a*b, y=-a*b, gg=__gcd(x, y);
cout << x/gg << "/" << y/gg << " " << (y/gg-x/gg) << "/" << y/gg << endl;
}
return ;
}