結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー parukiparuki
提出日時 2016-08-18 18:26:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,769 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 165,764 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 08:59:11
合計ジャッジ時間 3,127 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 |     }
      |     ^

ソースコード

diff #

#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;
    }
}
0