Created
October 22, 2014 13:15
-
-
Save wkentaro/34d81f665a28974385f1 to your computer and use it in GitHub Desktop.
code festa samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
# binary-tape.py | |
# handle inputs | |
T = int(raw_input()) | |
N, S = [], [] | |
for i in xrange(T): | |
N.append(int(raw_input())) | |
S.append(raw_input()) | |
# process | |
for N_i, S_i in zip(N, S): | |
count = 0 | |
start = 0 | |
end = 1 | |
while end <= len(S_i): | |
if int(S_i[start:end], 2) >= N_i: | |
count += 1 | |
start = end | |
end = start + 1 | |
else: | |
end += 1 | |
print count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
T = int(raw_input()) | |
N = [] | |
for i in xrange(T): | |
N.append(int(raw_input())) | |
for N_i in N: | |
count = 0 | |
while N_i != 1: | |
if N_i % 2 == 0: | |
N_i /= 2 | |
else: | |
N_i = N_i * 3 + 1 | |
count += 1 | |
print count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
# serve-t-shirts.py | |
# handle inputs | |
T = int(raw_input()) | |
x, y = [], [] | |
for i in xrange(T): | |
x.append(raw_input()) | |
y.append(raw_input()) | |
# process | |
for xi, yi in zip(x, y): | |
n_tshirts = [xi.count('S'), xi.count('M'), xi.count('L')] | |
n_people = [yi.count('S'), yi.count('M'), yi.count('L')] | |
# check for L people | |
if n_tshirts[2] < n_people[1]: | |
print 'NO' | |
continue | |
n_tshirts[2] -= n_people[2] | |
n_people[2] = 0 | |
# check for M people | |
# first M people put on L T-shirt | |
n_people[1] -= n_tshirts[2] | |
n_tshirts[2] = 0 | |
if n_tshirts[1] < n_people[1]: | |
print 'NO' | |
continue | |
n_tshirts[1] -= n_people[1] | |
n_people[1] = 0 | |
# check for S people | |
n_people[0] -= n_tshirts[1] | |
n_tshirts[1] = 0 | |
if n_tshirts[0] < n_people[0]: | |
print 'NO' | |
continue | |
n_tshirts[0] -= n_people[0] | |
n_people[0] = 0 | |
print 'YES' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment