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
1 1
2 3
3 3
4 4
Sample Output
0/1
1/3
1/3
3/16
此题相当于有两堆石头,你可以一次在任意一堆里取任意多,也可以在两堆里同时取一个
先用dp个表,然后就可以容易的看出规律了,
当一堆的数量是i的时候,只有当另一堆是唯一的一个j的时候才是先手必败的。所以把这些点存下来就好了。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<functional>
using namespace std;
typedef unsigned long long ull;
typedef long long LL;
const int maxn = 2e5 + 10;
int T, n, tot = 0, m;
struct point
{
int x, y;
point(int x, int y) :x(x), y(y){}
point(){}
}a[maxn];
int gcd(int x, int y)
{
return x%y ? gcd(y, x%y) : y;
}
void Init()
{
for (int i = 1; i <= 12000; i += 3)
{
a[tot++] = point(i, i + 1);
a[tot++] = point(i + 1, i);
a[tot++] = point(i + 2, i + 2);
}
}
int main()
{
Init();
while (scanf("%d%d", &n, &m) != EOF)
{
int ans = 0;
for (int i = 0; i < tot; i++)
{
if (n < a[i].x) break;
if (m >= a[i].y) ans++;
}
int k = ans ? gcd(ans, n*m) : 1;
printf("%d/%d\n", ans / k, n*m / k);
}
return 0;
}