結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー 158b
提出日時 2015-06-20 00:54:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,106 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 76,880 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2024-07-07 04:31:49
合計ジャッジ時間 7,951 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 8 TLE * 1 -- * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
using namespace std;

//#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vecy[4] = {0,-1,0,1};
const int Vecx[4] = {1,0,-1,0};
		
int main(){
    int t[3];
	int tes[3];
	int check;
	int sudare[10000];
	int cnt_s = 0;
	int cnt = 0;
	bool test[3];
	int ans1 = 1;
	int ans2 = 1;
	double loc[3];
	double check_loc;
	bool flg;
	int c1,c2,kouyaku;
	double check1,check2;
	
	
	for(int i=0; i<3; i++){
		cin >> t[i];
		tes[i] = t[i];
	}
	
	//最小公倍数を求める
	check = 2;
	while(check <= max(tes[0], max(tes[1],tes[2]))){
		cnt = 0;
		for(int i=0; i<3; i++){
			if(tes[i] % check == 0){
				test[i] = true;
				cnt ++;
			}else{
				test[i] = false;
			}
		}
		
		if(cnt >= 2){
			sudare[cnt_s] = check;
			cnt_s ++;
			for(int i=0; i<3; i++){
				if(test[i]){
					tes[i] /= check;
				}
			}
		}else{
			check ++;
		}
	}
	
	for(int i=0; i<cnt_s; i++){
		ans1 *= sudare[i];
	}
	for(int i=0; i<3; i++){
		ans1 *= tes[i];
	}
	
	for(int i=ans1; i>=1; i--){
		for(int ii=0; ii<3; ii++){
			loc[ii] = (ans1 / (double)i) / t[ii];
			loc[ii] = loc[ii] - floor(loc[ii]);
		}
		
		flg = true;
		check_loc = loc[0];

		for(int ii=1; ii<3; ii++){
			/*
		if(i == 18){
			cout << loc[ii] << "+" << check_loc << " == 1" << endl;
			cout << loc[ii] << " == " << check_loc << endl;
			cout << (loc[ii] + check_loc == 1) << endl;
		}
		*/
		check1 = loc[ii] + check_loc;
		check2 = loc[ii] - check_loc;
			if(!((check1 >= 0.9999 && check1 <= 1.0001) || (check2 >= -0.0001 && check2 <= 0.0001))){
				//cout << "out";
				flg = false;
				break;
			}else{
				//cout << "safe";
			}
		}
		if(flg){
			ans2 = i;
			break;
		}
	}
	//最大公約数を求める
	c1 = ans1;
	c2 = ans2;
	int amari;
	while(c2 != 0){
		amari = c1 % c2;
		c1 = c2;
		c2 = amari;
	}
	
	if(c1 != 1){
		ans1 /= c1;
		ans2 /= c1;
	}
	
	cout << ans1 << "/" << ans2;
	
    return 0;
}
0