結果
| 問題 |
No.229 線分上を往復する3つの動点の一致
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-18 18:26:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 2,769 bytes |
| コンパイル時間 | 1,931 ms |
| コンパイル使用メモリ | 169,488 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 19:30:17 |
| 合計ジャッジ時間 | 3,763 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
コンパイルメッセージ
main.cpp: In member function 'Fraction& Fraction::operator*=(const Fraction&)':
main.cpp:51:5: warning: no return statement in function returning non-void [-Wreturn-type]
50 | adjust();
+++ |+ return *this;
51 | }
| ^
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
struct Fraction{
long long n, d;
Fraction():n(0),d(1){ }
Fraction(long long n_, long long d_ = 1):n(n_), d(d_){ adjust(); }
bool operator<(const Fraction &x) const{ return n*x.d < x.n*d; }
bool operator<=(const Fraction &x) const { return n*x.d<=x.n*d; }
bool operator>(const Fraction &x) const{ return !(*this<=x); }
bool operator>=(const Fraction &x) const{ return !(*this<x); }
bool operator==(const Fraction &x) const{ return n*x.d==x.n*d; }
bool operator!=(const Fraction &x) const{ return n*x.d!=x.n*d; }
Fraction & operator+=(const Fraction &x){
n = x.d*n + d * x.n;
d *= x.d;
adjust();
return *this;
}
Fraction operator+(const Fraction &x) const{
Fraction res = *this;
res += x;
return res;
}
Fraction & operator-=(const Fraction &x){
return *this += Fraction(-x.n, x.d);
}
Fraction operator-(const Fraction &x) const{
Fraction res = *this;
res -= x;
return res;
}
Fraction & operator*=(const Fraction &x){
n *= x.n;
d *= x.d;
adjust();
}
Fraction operator*(const Fraction &x) const{
Fraction res = *this;
res *= x;
return res;
}
Fraction operator/=(const Fraction &x){
return *this *= Fraction(x.d, x.n);
}
Fraction operator/(const Fraction &x) const{
Fraction res;
res /= x;
return res;
}
void adjust(){
if(n == 0)d = 1;
if(d < 0)n = -n, d = -d;
auto g = gcd(n, d);
n /= g;
d /= g;
}
static long long gcd(long long a, long long b){ return b ? gcd(b, a%b) : a; }
};
Fraction calc(Fraction a, Fraction b){
ll D = a.d*b.d / Fraction::gcd(a.d, b.d);
ll N1 = a.n * D / a.d;
ll N2 = b.n * D / b.d;
ll num = D, den = Fraction::gcd(N1, N2);
return Fraction(num, den);
}
int main(){
ll T1, T2, T3;
while(cin >> T1 >> T2 >> T3){
Fraction f1(1, T1), f2(1, T2), f3(1, T3);
Fraction ans = calc(f1 + f2, f2 + f3);
smin(ans, calc(f1 - f2, f2 - f3));
smin(ans, calc(f1 - f2, f2 + f3));
smin(ans, calc(f1 + f2, f2 - f3));
cout << ans.n << '/' << ans.d << endl;
}
}