結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー ctyl_0ctyl_0
提出日時 2015-09-15 17:15:22
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,395 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2023-09-26 12:05:04
合計ジャッジ時間 7,739 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// a < b
ll gcd(ll a, ll b){
    if (a > b) {
        swap(a, b);
    }
    
    if (b % a == 0) {
        return a;
    }
    else{
        ll g = b % a;
        return gcd(g, a);
    }
}

// a < b
ll lcm(ll a, ll b){
    
    return (ll)a * (ll)b / (ll)gcd(a, b);
    
}
// first:分子 second:分母
// x = 6 / 5, y = 4 / 3: return: 12 / 1
pair<ll, ll> smallest(pair<ll, ll> x, pair<ll, ll> y){
    
    pair<ll, ll> ret;
    
    ret.second = lcm(x.second, y.second);
    ret.first = lcm(x.first * (ret.second / x.second), y.first * (ret.second / y.second));
    
    ll g = gcd(ret.first, ret.second);
    
    ret.first /= g;
    ret.second /= g;
    
    return ret;
}

int main(int argc, const char * argv[]) {
    
    // source code
    vector<ll> T(3);
    rep(i, 3){
        T[i] = (ll)inputValue();
    }
    
    sort(T.begin(), T.end());
    
    vector<pair<ll, ll> > M(4);
    
    M[0] = smallest(make_pair(T[0] * T[1], T[0] + T[1]), make_pair(T[0] * T[2], T[0] + T[2]));
    
    M[1] = smallest(make_pair(T[0] * T[1], T[0] + T[1]), make_pair(T[0] * T[2], T[2] - T[0]));
    
    M[2] = smallest(make_pair(T[0] * T[1], T[1] - T[0]), make_pair(T[0] * T[2], T[0] + T[2]));
    
    M[3] = smallest(make_pair(T[0] * T[1], T[1] - T[0]), make_pair(T[0] * T[2], T[2] - T[0]));
    
    vector<double> D(4);
    int ii = 0;
    double min = (double)M[0].first / (double)M[0].second;
    
    rep(i, 4){
        D[i] = (double)M[i].first / (double)M[i].second;
        if (min > D[i]) {
            min = D[i];
            ii = i;
        }
    }
    
    cout << M[ii].first << "/" << M[ii].second << endl;
    
    return 0;
}
0