1417 天堂里的游戏

 

思路:看了很久才知道题意,虽然51nod分类为博弈,但我感觉还是不像。解法已经隐藏在样例中了,无论正还是反,最后的期望都是一样的。设美女正面的概率为p,反面为(1-p)则

p*A-(1-p)*(A+B)/2 = (1-p)*B-p*(A+B)/2,解得:P=(A+3*B)/(4A+4B),最后取下gcd求最简即可。

 1 #include <iostream>
 2 #include <queue>
 3 #include <stack>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <map>
 7 #include <set>
 8 #include <bitset>
 9 #include <algorithm>
10 #include <cmath>
11 #include <cstring>
12 #include <cstdlib>
13 #include <string>
14 #include <sstream>
15 #include <time.h>
16 #define x first
17 #define y second
18 #define pb push_back
19 #define mp make_pair
20 #define lson l,m,rt*2
21 #define rson m+1,r,rt*2+1
22 #define mt(A,B) memset(A,B,sizeof(A))
23 #define mod 1000000007
24 using namespace std;
25 typedef long long LL;
26 const double PI = acos(-1);
27 const int N=2e5+10;
28 const int inf = 0x3f3f3f3f;
29 const LL INF=0x3f3f3f3f3f3f3f3fLL;
30 LL gcd(LL a,LL b)
31 {
32     return b==0?a:gcd(b,a%b);
33 }
34 int main()
35 {
36 #ifdef Local
37     freopen("data.txt","r",stdin);
38 #endif
39     int T;
40     LL a,b;
41     cin>>T;
42     while(T--)
43     {
44         cin>>a>>b;
45         LL p=a+3*b;
46         LL q=4*(a+b);
47         LL k=gcd(p,q);
48         cout<<p/k<<"/"<<q/k<<endl;
49     }
50 #ifdef Local
51     cerr << "time: " << (LL) clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
52 #endif
53 }
View Code

 

posted @ 2017-01-10 01:11  Kcl886  阅读(193)  评论(0编辑  收藏  举报