D - 凤神与狗
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
Input
第一行包含5个整数:c(0<c≤1000000),d(0<d≤1000000),w(0<w≤1000000),a(0<a<1000000),b(a<b≤1000000)Output
答案用最简分数表示,x/y,x为分子,y为分母。Sample input and output
| Sample Input | Sample Output |
|---|---|
1 1 1 1 2 |
1/3 |
这是第i天和第i+2天都带狗的概率。
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
/*long long gcd(long long x, long long y)
{
long long r;
while (y > 0)
{
r = x%y;
x = y;
y = r;
}
return x;
}*/
long long int gcd(long long int x, long long int y)
{
while (x != y)
{
if (x>y) x = x - y;
else
y = y - x;
}
return x;
}
int main()
{
long long c, d, w, a, b;
scanf("%lld %lld %lld %lld %lld", &c, &d, &w, &a, &b);
long long x, y, xy;
// x = d*d + d*(b - a)*w;
// y = c*c + 2 * c*d + d*d + (c + d)*(b - a)*w;
x = d*(d + w);
y = (c + d)*(c + d + w);
// cout<<x<<" "<<y<<endl;
xy = gcd(x, y);
x /= xy;
y /= xy;
printf("%lld/%lld", x, y);
return 0;
}
511



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



