-
Notifications
You must be signed in to change notification settings - Fork 0
/
routine_problem.cpp
63 lines (52 loc) · 1.15 KB
/
routine_problem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* https://codeforces.com/contest/337/problem/B
*/
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
long gcd(long a, long b)
{
if (a == 0)
return b;
else if (b == 0)
return a;
if (a < b)
return gcd(a, b % a);
else
return gcd(b, a % b);
}
int main()
{
int a, b, c, d;
cin >> a >> b >> c >> d;
//Fit height
double height_ratio = (double) b / (double) d;
//Fit width
double width_ratio = (double) a / (double) c;
if (c*height_ratio > a) {
height_ratio = -1;
}
if (d*width_ratio > b) {
width_ratio = -1;
}
double height_area = 0;
double width_area = 0;
if (height_ratio > 0) {
height_area = height_ratio*(c+d);
}
if (width_ratio > 0) {
width_area = width_ratio*(c+d);
}
long numerator = 0, denominator = 0;
if (height_area > width_area) {
numerator = d*a-c*b;
denominator = a*d;
}
else {
numerator = b*c-d*a;
denominator = b*c;
}
long _gcd = gcd(numerator, denominator);
cout << numerator/_gcd << "/" << denominator/_gcd << endl;
}