結果

問題 No.356 円周上を回る3つの動点の一致
コンテスト
ユーザー mamekin
提出日時 2016-04-01 22:59:59
言語 C++14
(gcc 13.3.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 2,661 bytes
記録
コンパイル時間 1,065 ms
コンパイル使用メモリ 105,544 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-02 09:18:29
合計ジャッジ時間 2,286 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class Fraction
{
private:
    long long n; // 分子(numerator)
    long long d; // 分母(denominator)

    // 約分
    void reduce(){
        if(d < 0){
            n *= -1;
            d *= -1;
        }
        long long a = abs(n);
        long long b = d;
        while(b != 0){
            long long tmp = a % b;
            a = b;
            b = tmp;
        }
        n /= a;
        d /= a;
    }
public:
    Fraction(){
        n = 0;
        d = 1;
    }
    Fraction(long long n0){
        n = n0;
        d = 1;
    }
    Fraction(long long n0, long long d0){
        n = n0;
        d = d0;
        reduce();
    }
    pair<long long, long long> getValue() const{
        return make_pair(n, d);
    }
    const Fraction operator+(const Fraction& f) const{
        return Fraction(n*f.d + d*f.n, d*f.d);
    }
    const Fraction operator-(const Fraction& f) const{
        return Fraction(n*f.d - d*f.n, d*f.d);
    }
    const Fraction operator*(const Fraction& f) const{
        return Fraction(n*f.n, d*f.d);
    }
    const Fraction operator/(const Fraction& f) const{
        return Fraction(n*f.d, d*f.n);
    }
    bool operator==(const Fraction& f) const{
        return n == f.n && d == f.d;
    }
    bool operator!=(const Fraction& f) const{
        return n != f.n || d != f.d;
    }
};

// 最大公約数
long long gcd(long long a, long long b){
    while(b != 0){
        long long tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

// 最小公倍数
long long lcm(long long a, long long b){
    return a / gcd(a, b) * b;
}

int main()
{
    vector<Fraction> f(3);
    for(int i=0; i<3; ++i){
        int t;
        cin >> t;
        f[i] = Fraction(1, t);
    }

    for(int j=0; j<2; ++j){
        vector<Fraction> d(f.size()-1);
        for(unsigned i=0; i<f.size()-1; ++i){
            if(f[i] == f[i+1]){
                d[i] = f[i];
            }
            else{
                d[i] = f[i] - f[i+1];
                if(d[i].getValue().first < 0)
                    d[i] = d[i] * -1;
            }
        }
        f.swap(d);
    }

    Fraction ans = Fraction(1) / f[0];
    cout << ans.getValue().first << '/' << ans.getValue().second << endl;

    return 0;
}
0