Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tzengyuxio
Created April 13, 2014 08:23
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/10574475 to your computer and use it in GitHub Desktop.
Save tzengyuxio/10574475 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
# 計算建完 n 個農場所需時間
def calc_time(c, f, n):
tt = 0.0
for i in range(n):
tt += (c / (2 + i * f))
return tt
def solve():
s = sys.stdin.readline()[:-1]
c, f, x = [float(x) for x in s.split()]
n = (int)(((x * f - c - c) / (c * f) ) - 1) + 1 # 最佳解時的農場數量
postfix = " >>" + repr(n)
if n <= 1:
t = (x / 2)
else:
t = calc_time(c, f, n) + (x / (2 + n * f))
return repr(round(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