Skip to content

Instantly share code, notes, and snippets.

@tzengyuxio
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzengyuxio/10570939 to your computer and use it in GitHub Desktop.
Save tzengyuxio/10570939 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#
# author: tzeng.yuxio@gmail.com
# usage: cat file.input | ./qround-problem-a.py > file.output
import sys
def solve():
s = sys.stdin.readline()[:-1]
c, f, x = [float(x) for x in s.split()]
min_t = x / 2 # 達到 x cookie 的最小時間, 一開始沒有 farm, 所以直接除 2
pass_t = 0 # 生產 n 個 farm 所需的經過時間(累積時間)
num_farm = 0 # farm 的數量
while pass_t < min_t: # 如果生產 farm 所需的時間比目前得到的最小時間更大就停止, 因為之後不可能更小了
prod = 2 + num_farm * f # production, 目前產量
pass_t += (c / prod) # 增加一個 farm 所需的時間
num_farm += 1 # farm 數量
this_t = pass_t + (x / (prod + f)) # this_t, 在 num_farm 的情形下 (產量為 prod+f),達到 x 所需的時間
min_t = min(min_t, this_t) # 更新達到 x 所需的最小時間
return repr(round(min_t, 7))
t = (int)(sys.stdin.readline())
for i in range(t):
print 'Case #' + repr(i+1) + ': ' + solve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment