Rikka with Stone-Paper-Scissors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 438    Accepted Submission(s): 203


 

Problem Description

Did you watch the movie "Animal World"? There is an interesting game in this movie.

The rule is like traditional Stone-Paper-Scissors. At the beginning of the game, each of the two players receives several cards, and there are three types of cards: scissors, stone, paper. And then in each round, two players need to play out a card simultaneously. The chosen cards will be discarded and can not be used in the remaining part of the game.

The result of each round follows the basic rule: Scissors beat Paper, Paper beats Stone, Stone beats Scissors. And the winner will get 1 point, the loser will lose 1 point, and the points will not change in the case of a draw.

Now, Rikka is playing this game with Yuta. At first, Yuta gets a Scissors cards, b Stone cards and c Paper cards; Rikka gets a′ Scissors cards, b′ Stone cards, c′ Paper cards. The parameters satisfy a+b+c=a′+b′+c′ . And then they will play the game exactly a+b+c rounds (i.e., they will play out all the cards).

Yuta's strategy is "random". Each round, he will choose a card among all remaining cards with equal probability and play it out.

Now Rikka has got the composition of Yuta's cards (i.e., she has got the parameters a,b,c ) and Yuta's strategy (random). She wants to calculate the maximum expected final points she can get, i.e., the expected final points she can get if she plays optimally.

Hint: Rikka can make decisions using the results of previous rounds and the types of cards Yuta has played.

 

 

Input

The first line contains a single number t(1≤t≤104) .

For each testcase, the first line contains three numbers a,b,c and the second line contains three numbers a′,b′,c′(0≤a,b,c,a′,b′,c′≤109,a+b+c=a′+b′+c′>0) .

 

 

Output

For each testcase, if the result is an integer, print it in a line directly.

Otherwise, if the result equals to ab(|gcd(a,b)|=1,b>0, a and b are integers) , output "a /b " (without the quote) in a single line.

 

 

Sample Input

 

4 2 0 0 0 2 0 1 1 1 1 1 1 1 0 0 0 0 1 123 456 789 100 200 1068

 

 

Sample Output

 

2

0

-1

3552/19

题意:两个人,各有不同的石头剪刀布数量,两个人来猜拳,问第一个人的最大分是多少,像这种游戏原本就是平衡的求得分的情况,直接就是 出石头赢的分剪去出石头输的分,继续加上剪刀赢的分和剪刀输的分,继续加上出布赢的分,剪去出布输的分 所以方程就出来了:(ac'-ab'+ba'-bc'+cb'-ca')/n;

Otherwise, if the result equals to ab(|gcd(a,b)|=1,b>0, a and b are integers) , output "a /b " (without the quote) in a single line.

这句话的要求就是 能整除就整除,不能整除就分母输出且化简

 

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cmath>
#include<assert.h>
#include<map>
#include<cstring>
#define in(a) scanf("%d",&a) 
#define ind(a) scanf("%lld",&a)
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int main()
{
	int t;
	in(t);
	while(t--)
	{
		ll a[3],b[3];
		for(int i=0;i<3;i++) ind(a[i]);
		for(int i=0;i<3;i++) ind(b[i]);
		ll ans=0;
		ll n=a[0]+a[1]+a[2];
		for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			if(j==(i+1)%3) ans+=a[i]*b[j];
			else if(i!=j)  ans-=a[i]*b[j];
		int d=abs(gcd(n,ans));
		if(ans%n==0) printf("%lld\n",ans/n);
		else printf("%lld/%lld\n",ans/d,n/d);
	}
}