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.

 
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
 
题意: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;
}

  

最新文章

  1. github fork后的pull和保持同步
  2. 移动适配请使用比rem等更好的布局方案
  3. AngularJS控制器
  4. OC- @property @synthesize
  5. Visual Studio 2013 Update 2 and with Update 2
  6. java poi导入EXCEL xls文件代码
  7. Delphi 常用属性说明(超长)
  8. linux下一个C语言flock功能使用 .
  9. 写入cookie后只显示一次的DIV提示框代码
  10. 计算机程序的思维逻辑 (79) - 方便的CompletionService
  11. 解决跨站脚本注入,跨站伪造用户请求,sql注入等http安全漏洞
  12. rem ~~ 你懂了吗?
  13. 高质量的内容是SEO的关键
  14. SQLServer之修改UNIQUE约束
  15. 关于confluence上传文件附件预览查看时出现乱码的问题解决办法
  16. Vue学习4:class与style绑定
  17. vue实例的生命周期
  18. 剑指offer 3. 链表 从尾到头打印链表
  19. httpd基础知识
  20. vetur插件提示 [vue-language-server] Elements in iteration expect to have &#39;v-bind:key&#39; directives

热门文章

  1. 【iOS】iOS CocoaPods 整理
  2. Unity基础之:UnityAPI的学习
  3. n的阶乘 -牛客
  4. charles(version4.2.1)抓包手机数据
  5. element ui 登录验证,路由守卫
  6. java高并发系列 - 第27天:实战篇,接口性能成倍提升,让同事刮目相看,现学现用
  7. .net软件开发脚本规范-SQL脚本标准
  8. 【java提高】(18)---静态内部类和非静态内部类
  9. Keras载入mnist数据集出错问题解决方案
  10. QMS 的趨勢概述