Rikka with Stone-Paper-Scissors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1 Accepted Submission(s): 1
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 1point, 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.
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 1point, 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).
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.
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
题意:A分别有a1,b1,c1个剪刀,石头,布,B分别有a2,b2,c2个剪刀,石头,布,B胜A获得一分,平手不得不失,A输B失去一分,求B得到最大分数的期望
分析:B要获得最大分数,则在A出剪刀的时候B一定要出石头,此时B可以得到胜A的分数但是同时会失去A可能出布失去的分数
则A出剪刀时B得分的期望是:b2*a1/(a1+b1+c1) - b2*c1/(a1+b1+c1) 依次类推
所以B获胜的期望是:(a1*b2-b2*c1+b1*c2-a1*c2+a2*c1-a2*b)/(a1+b1+c1)
最后化简下分数
AC代码:
#include <map> #include <set> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define ls (r<<1) #define rs (r<<1|1) #define debug(a) cout << #a << " " << a << endl using namespace std; typedef long long ll; const ll maxn = 1e6+10; const ll mod = 998244353; const double pi = acos(-1.0); const double eps = 1e-8; ll gcd( ll a, ll b ) { if( a == 0 ) { return b; } if( b == 0 ) { return a; } return gcd(b%a,a); } int main() { ios::sync_with_stdio(0); ll T; cin >> T; while( T -- ) { ll a1, b1, c1, a2, b2, c2; cin >> a1 >> b1 >> c1; cin >> a2 >> b2 >> c2; ll t = a1*b2-b2*c1+b1*c2-a1*c2+a2*c1-a2*b1; ll num = a1+b1+c1; if( t%num == 0 ) { cout << t/num << endl; } else { if( t < 0 ) { //注意求最大公约数时数为负数的情况 cout << t/gcd(-t,num) << "/" << num/gcd(-t,num) << endl; } else { cout << t/gcd(t,num) << "/" << num/gcd(t,num) << endl; } } } return 0; }