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 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
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
typedef long long llt;
using namespace std;
llt gcd(llt x,llt y)
{
return (y==0)?x:gcd(y,x%y);
}
int main(){
int T;
llt a[3][5];
scanf("%d",&T);
while(T--)
{
for(int i=1;i<=2;++i)
{
for(int j=1;j<=3;++j)
{
scanf("%lld",&a[i][j]);
}
}
llt sum = 0;
for(int i=1;i<=3;++i) sum += a[1][i];
a[1][0] = a[1][3];
a[2][0] = a[2][3];
llt f1=0;
for(int i=1;i<=3;++i)
f1 += a[2][i]*a[1][i-1];
llt f2=0;
for(int i=1;i<=3;++i)
f2+= a[1][i]*a[2][i-1];
llt y = sum;
llt x = (f1-f2);
llt fgcd= gcd(abs(x),y);
y/=fgcd;
x/=fgcd;
if(y==1)printf("%lld\n",x);
else if(x==0) printf("0\n");
else printf("%lld/%lld\n",x,y);
}
return 0;
}
本文介绍了一个基于电影《动物世界》中的纸-石头-布游戏策略问题。该问题涉及两个玩家之间的策略对决,其中一个玩家采取随机策略,而另一个玩家试图通过最优策略获得最大的预期分数。文章探讨了如何通过数学计算来确定最优策略。
826

被折叠的 条评论
为什么被折叠?



