#!/usr/bin/python
"""
26 名前:デフォルトの名無しさん[sage] 投稿日:2014/06/15(日) 21:35:27.50 ID:lBQJsMnk
地球の周りを3つの衛星が回っています
衛星Aは1時間23分かけて地球一周できます
衛星Bは3時間9分かけて地球一周できます
衛星Cは5時間45かけて地球一周できます
衛星は同じ位置にくると自動的によけてくれるので衝突して故障することはありません。速度も一定に移動します。
衛星Aは60度の位置、衛星Bは192度の位置、衛星Cは265の位置からスタートする。
3つの衛星が同じ位置に重なりあうのは何時間後か求めて出力せよ。また、重なりあうまで何周したかそれぞれ出力せよ。
"""
from fractions import Fraction
from fractions import gcd
lcm = lambda a,b: a*b/gcd(a,b)
class Satellite:
def __init__(self, id, period, phase, t=0):
self.name = chr(ord("A")+id)
self.period = Fraction(period)
self.phase = Fraction(phase)
self.t = Fraction(t)
def __str__(self):
return "{0.name}:per={0.period},pha={0.phase},time={0.t}".format(self)
def merge(a,b):
# print a,b
# 古い方の時間を進める
if not a.t < b.t:
a, b = b, a
a.phase = (a.phase + (b.t - a.t) * 360 / a.period) % 360
a.t = b.t
# 追いつくまでの時間
if not a.period < b.period:
a, b = b, a
delta = ((b.phase - a.phase) % 360) / 360 / (1/a.period - 1/b.period)
# 重なるところまで移動
for s in [a, b]:
s.t += delta
s.phase = (s.phase + s.t * 360 / s.period) % 360
# print a, b, delta
# 1つの仮想の天体として返す
return Satellite(-1, lcm(a.period, b.period), a.phase, a.t)
def f26(sats_inf):
sats = [Satellite(i, s[0]*60+s[1], s[2]) for (i,s) in enumerate(sats_inf)]
uni = reduce(merge, sats)
print "t={}(h)\npha={}(degree)".format(float(uni.t/60), float(uni.phase))
print "-"*3
for s in sats:
print "{0.name}:{1}(cyc)".format(s, float(uni.t / s.period))
q = [[1,23,60],[3,29,192],[5,45,265]]
#q = [[3,0,60],[6,0,0],]
f26(q)
IyEvdXNyL2Jpbi9weXRob24KCiIiIgoyNiDlkI3liY3vvJrjg4fjg5Xjgqnjg6vjg4jjga7lkI3nhKHjgZfjgZXjg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