题目描述
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Y W D三个要去旅游,三个人有各自想去的地方,于是投六面筛子决定,点数最大的胜利。若已知Y W的点数,求D胜利的概率。(若Y W的点数与D相同,作为绅士,他们会让D赢)
代码
#include <iostream>
using namespace std;
//最大公约数
int gcd(int n, int m) {
if (m == 0) return n;
else if (n % m == 0) return m;
else return gcd(m, n % m);
}
int main(){
int Y = 1, W = 1 ,D = 1;
while(cin >> Y >> W){
int max = 0;//比较器
int i = 0;//概率计数器
if(Y>=W) max = Y;
else max = W;
//统计可能赢的点数
for(D = 1; D <= 6 ; D++){
if(D >= max){
i++;
}
}
//约分
cout << i/gcd(i,6) << "/" << 6/gcd(i,6) << endl;
}
return 0;
}