marshmallow (博弈论)
2016-02-27 19:36
387 查看
Description
Jack’s girlfriend loves marshmallow very much, so he buys her two bags of marshmallow on the Children’s Day. One of them is made up of red one’s, whose number is about n, and the other is blue with number of m. Suddenly Jack comes up with an idea that he can
play a game with his girlfriend and test her IQ as well. So he takes some marshmallow out from the red one’s, together from the blue one’s, and puts them on the table. Now it begins with his girlfriend, she picks up the marshmallow on the table and eats them,
then it’s Jack’s turn, after Jack, his girlfriend chooses, then Jack…… it goes on like this, but they have to follow some disciplines. Every time, he or his girlfriend can take away 1.any number of red one’s 2.any number of blue one’s 3.a red one, together
with a blue one, is a must and he or she can be the winner if he or she takes away the last one. Jack considers that he is the second to none smartest guy in the world, what surprises him is that his girlfriend is also very smart, which makes Jack feel embarrassed……
Assuming that there are red marshmallow and blue marshmallow on the table, whose numbers are i(1 <= i< =n) and j(1 <= j <= m) , and such situation’s probability is 1/(n * m). Jack wants to know how much probability he has to win the game.
Input
Group data, and each group is made up of two positive integer n and m (1 <= n, m <= 10000)
Output
Output Jack’s probability of winning the game with irreducible fraction, if he has no chance to win, please output 0/1
Sample Input
Sample Output
Jack’s girlfriend loves marshmallow very much, so he buys her two bags of marshmallow on the Children’s Day. One of them is made up of red one’s, whose number is about n, and the other is blue with number of m. Suddenly Jack comes up with an idea that he can
play a game with his girlfriend and test her IQ as well. So he takes some marshmallow out from the red one’s, together from the blue one’s, and puts them on the table. Now it begins with his girlfriend, she picks up the marshmallow on the table and eats them,
then it’s Jack’s turn, after Jack, his girlfriend chooses, then Jack…… it goes on like this, but they have to follow some disciplines. Every time, he or his girlfriend can take away 1.any number of red one’s 2.any number of blue one’s 3.a red one, together
with a blue one, is a must and he or she can be the winner if he or she takes away the last one. Jack considers that he is the second to none smartest guy in the world, what surprises him is that his girlfriend is also very smart, which makes Jack feel embarrassed……
Assuming that there are red marshmallow and blue marshmallow on the table, whose numbers are i(1 <= i< =n) and j(1 <= j <= m) , and such situation’s probability is 1/(n * m). Jack wants to know how much probability he has to win the game.
Input
Group data, and each group is made up of two positive integer n and m (1 <= n, m <= 10000)
Output
Output Jack’s probability of winning the game with irreducible fraction, if he has no chance to win, please output 0/1
Sample Input
1 1 2 3 3 3 4 4
Sample Output
0/1 1/3 1/3 3/16
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<set> #include<vector> #include<map> #include<cmath> using namespace std; typedef long long ll; const int inf = 0x3f3f3f3f; const int N = 100000 + 10; int main() { int n,m,a,b; while(cin>>n>>m) { if(n==1 && m==1) cout<<"0/1"<<endl; else { a=min(n,m); b=n*m; if(n==m && (n-1)%3==0) a--; cout<<a/__gcd(a,b)<<"/"<<b/__gcd(a,b)<<endl; } } return 0; }
相关文章推荐
- poj 2533 Longest Ordered Subsequence
- Atitit.code base view 视图的实现原理
- html5 postMessage解决跨域、跨窗口消息传递
- Emergency relief (枚举+状态压缩)
- leetcode:字符串
- Struts2学习笔记之自定义转换器
- 问卷调查
- Knots (组合数学)
- leetcode:线性表
- NYOJ 孪生素数问题
- BlueTooth: 蓝牙协议栈实现模式分析
- 263. Ugly Number
- Hanoi Tower Troubles Again! (找规律)
- leetcode:其他
- win10java环境配置
- GetPostBackEventReference加RaisePostBackEvent实现自定义控件中回调传参
- 解析this.initialize.apply(this, arguments);
- asp.net对cookie的操作
- 主成分分析法
- 使用Python的SnowNLP模块实现情感分析