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/10570957 to your computer and use it in GitHub Desktop.
Save tzengyuxio/10570957 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#
# author: tzeng.yuxio@gmail.com
# usage: cat file.input | ./qround-problem-d.py > file.output
import sys
def solve():
numblocks = (int)(sys.stdin.readline())
s = sys.stdin.readline()[:-1]
wn = [float(x) for x in s.split()] # weights of Noami
s = sys.stdin.readline()[:-1]
wk = [float(x) for x in s.split()] # weights of Ken
wn.sort()
wk.sort()
str_dwar = ""
while wn or wk:
if not wn:
str_dwar += "X" # Chorus A
wk.pop() # 副歌 A 段
elif not wk:
str_dwar += "O" # Chorus B
wn.pop() # 副歌 B 段
elif wn[-1] > wk[-1]:
str_dwar += "O" # Chorus B
wn.pop() # 副歌 B 段
else:
str_dwar += "X" # Chorus A
wk.pop() # 副歌 A 段
naomi_count = 0
ken_count = 0
naomi_win = 0
ken_win = 0
for c in str_dwar:
if c == 'O': # 上面兩段 Chorus B 的兩行,可以直接用以下四行替代
naomi_count += 1
if ken_count > 0:
ken_count -= 1
ken_win += 1
else: # 上面兩段 Chorus A 的兩行,可以直接用以下四行替代
ken_count += 1
if naomi_count > 0:
naomi_count -= 1
naomi_win += 1
return repr(naomi_win) + " " + repr(numblocks - ken_win)
# return str_dwar
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