This is a solution to the Code Jam 2014 Qualification Round problem B, Cookie Clicker Alpha.
(Problem Description Link)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
__author__ = 'Coddicted' def read_case(inf): return inf.readline().split(' ') def write_case(f, i, res): f.write('Case #%d: '%i) f.write('%.7f'%res) f.write('\n') def main(): with open('data_files/B-large-practice.in', 'r') as inf, open('data_files/B-large-practice.out', 'w') as of: t = int(inf.readline()) case_cnt = 1 while case_cnt <= t: c, f, x = read_case(inf) c = float(c) f = float(f) x = float(x) #print str(c) + ':' + str(f) + ':' + str(x) if c > x: #print x/2 #of.write('Case #' + str(case_cnt) + ': ' + str(x/2) + '\n') write_case(of, case_cnt, x/2) case_cnt += 1 continue curr_t = x/2 prev_t = 0 pr_rate = 2 while True: new_t = prev_t + c/pr_rate + x/(f+pr_rate) #print new_t if new_t < curr_t: curr_t = new_t prev_t += c/pr_rate pr_rate += f else: break #print curr_t #of.write('Case #' + str(case_cnt) + ': ' + str(deceitful_score) + ' ' + str(war_score) + '\n') write_case(of, case_cnt, curr_t) case_cnt += 1 main() |
The sample input file(s) are available on the Problem link above.