結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー 158b158b
提出日時 2015-06-20 00:54:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,106 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 76,448 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 10:26:22
合計ジャッジ時間 9,024 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 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 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 771 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 5 ms
4,380 KB
testcase_16 WA -
testcase_17 TLE -
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 <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