51Nod Games in Paradise

Years later, whenever Noder sees a gypsies, he thinks of that distant afternoon.

 

Noder lay on the grass and stared aimlessly. The cafe on the second floor shone brightly in the sunlight, as if it was about to evolve into a giant coffee bean. The weather was a little cold, but the grass was still warm. Not far away sat a gypsy girl with tarot cards in her hand and headphones, with her dog beside her. The dog looks a bit fierce, but the girl is beautiful. Noder began to calculate the success probability of various ways to strike up a conversation, but the existence of dogs... .

 

Strange things happened, and the girl came over by herself and put headphones on Noder's ears, which played: "...Knock-knock-knockin' on heaven's door...". The girl gave him a weird smile, and Noder only felt a dizziness in front of him, and then he stood at the gate of heaven.

 

When Noder was in shock, a beautiful woman came and asked to play a math game with him. The beauty suggested: "Let's each show one side of the coin, heads or tails. If we're both heads, I'll give you $A, and if we're all tails, I'll give you $B (A+B is an even number). For the rest, you can give me (A + B) / 2 yuan.

 

Noder knew that he was going to lose most of the game, but he didn't care, he just wanted to make himself lose slower.

 

So let's help the beauty calculate, what is the probability that she will choose a positive (output in the form of the simplest fraction)?

 

When Noder woke up from the grass after losing all his money, the gypsy girl was gone, leaving only a tarot card with a picture of the beauty on it.

 

 

Explanation about the example:

 

The beauty adopted (3/8, 5/8) this plan, no matter what plan Noder adopts, it cannot change the situation. If all heads come up, the expected return each time is (3+3+3-2-2-2-2-2)/8=-1/8 yuan; if all tails come out, the expected return each time is also (- 2-2-2+1+1+1+1+1)/8=-1/8 yuan. And any strategy is nothing more than a linear combination of the above two strategies, so the expectation is still -1/8 yuan.

Input
Line 1: A number T representing the number of numbers to use later as input tests (1 <= T <= 20).
Line 2 - T + 1: Each line contains 2 numbers A, B separated by spaces. (1 <= A, B <= 10^9, and A + B is even).
Output
A total of T lines are output, corresponding to the probability that the beauty chooses the front, and the output is in the form of the simplest fraction. For details, please refer to the output example.
Input example
2
3 1
1 3
Output example
3/8
5/8 
Let C=(A+B)/2;
so according to the example, An-C(mn)==B(mn)-Cn ==> m=A+B+2C|||||| n=B+C;
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) ((a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll x,ll y)
{
    return y== 0 ?x:gcd(y,x% y);
}
intmain ()
{
    ll A,B,t;
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld%lld",&A,&B);
        ll m=A+A+B+B;
        ll n=B+(A+B)/2;
        ll c=gcd(n,m);
        printf("%lld/%lld\n",n/c,m/c);
    }
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325099047&siteId=291194637