카테고리 없음
2012 Google code Jam: Problem B. Dancing With the Googlers
반응형
1. 2012 Google code Jam: Problem B. Dancing With the Googlers
https://code.google.com/codejam/contest/dashboard?c=1460488#s=p1
2. 풀이 코드
class util_file_writer:
def __init__(self, file_name, flag):
self.file_name = file_name
self.fd = open(file_name, flag)
def __del__(self):
self.fd.close()
def write_case_int(self, idx, val):
self.fd.write('Case #')
self.fd.write(str(idx + 1))
self.fd.write(': ')
self.fd.write(str(val))
self.fd.write("\n")
def print_case_int_val(idx, val):
print("Case #", end="")
print(idx + 1, end="")
print(":", end=" ")
print(val)
def remove_white_space(one_line):
# remove white space
test_input = []
one_item = []
one_left = False
for i in one_line:
if i != ' ':
one_item.append(i)
one_left = True
else:
temp_str = ""
for part_one_item in one_item:
temp_str += part_one_item
test_input.append(temp_str)
one_item = []
one_left = False
if True == one_left:
temp_str = ""
for part_one_item in one_item:
temp_str += part_one_item
test_input.append(temp_str)
one_item = []
one_left = False
return test_input
in_file = open('./input/B-large-practice.in', 'r')
#in_file = open('./input/problem2.txt', 'r')
num_test = int(in_file.readline())
def handle_one_line(num_test, one_line):
test_input = remove_white_space(one_line)
num_googlers = int(test_input[0])
num_surp = int(test_input[1])
score_p = int(test_input[2])
limit_score = score_p
score_set = []
for ns in range(num_googlers - num_surp):
if score_p >= 1:
score_set.append(score_p + ((score_p - 1)*2))
else:
score_set.append(score_p*2)
for s in range(0, num_surp):
limit_score = score_p
for i in range(0, 2):
if score_p >= 2:
limit_score += score_p - 2
score_set.append(limit_score)
num_over_p = 0
if num_googlers > 0:
googlers_input = test_input[3:]
for each_googler_score in googlers_input:
idx = 0
found = False
temp_score_set = score_set
for score in temp_score_set:
if score <= int(each_googler_score):
num_over_p += 1
#print(num_over_p)
del temp_score_set[idx]
found = True
break
idx += 1
if False == found:
del temp_score_set[0]
return num_over_p
util_file = util_file_writer("./output.txt", 'w')
for test_cnt in range(num_test):
one_line = in_file.readline()
val = handle_one_line(test_cnt, one_line)
print_case_int_val(test_cnt, val)
util_file.write_case_int(test_cnt, val)
in_file.close()
반응형
댓글