結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー koyumeishikoyumeishi
提出日時 2015-06-20 15:01:15
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,518 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 81,324 KB
実行使用メモリ 13,048 KB
最終ジャッジ日時 2023-09-21 22:04:19
合計ジャッジ時間 15,079 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
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 <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

long long gcd(long long a, long long b){
	if(b==0) return a;
	return gcd(b, a%b);
}

long long lcm(long long a, long long b){
	if(a<b) swap(a,b);
	if(b==1) return a;
	return a * (b/gcd(a,b));
}

struct fraction{
	long long N;
	long long D;
	fraction(long long n, long long d){
		N = n;
		D = d;
		long long g = gcd(N,D);
		N /= g;
		D /= g;
	}
	fraction(){

	}
	fraction operator*(const fraction& x){
		return fraction(this->N * x.N, this->D * x.D);
	}

	bool operator<(const fraction& x) const{
		long long l = lcm(this->D, x.D);
		return (this->N * (l/this->D)) < (x.N * (l/x.D));
	}

	void print(){
		cerr << N << "/" << D << endl;
	}

};

int main(){
	vector<long long> T(3);
	for(int i=0; i<3; i++){
		cin >> T[i];
	}

	vector<fraction> ans(4);
	for(int i=0; i<4; i++){
		vector<long long> A(2), B(2);
		vector<long long> N(2), D(2);
		vector<long long> g(2);

		A[0] = T[1] + T[0] * ((i&1)?1:-1);
		B[0] = T[1] * T[0];

		A[1] = T[2] + T[1] * ((i&2)?1:-1);
		B[1] = T[2] * T[1];

		for(int k=1; ; k++){
			fraction t(B[0] * k, A[0]);
			fraction tmp(A[1], B[1]);

			tmp = tmp * t;

			if(tmp.D == 1){
				ans[i] = t;
				break;
			}
		}
	}

	sort(ans.begin(), ans.end());
	cout << ans[0].N << "/" << ans[0].D << endl;
/*
	for(int i=0; i<4; i++){
		cerr << ans[i].N << "/" << ans[i].D << endl;
	}
*/
	return 0;
}
0