結果

問題 No.356 円周上を回る3つの動点の一致
ユーザー mamekinmamekin
提出日時 2016-04-01 22:59:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,661 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 106,368 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 07:34:31
合計ジャッジ時間 2,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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