Last active
April 9, 2017 09:34
-
-
Save hcpl/13547ac8a9ae81edbaf1a683b09e8a4b to your computer and use it in GitHub Desktop.
A formula solution for Google Code Jam 2017 problem C (Bathroom Stalls)
This file contains hidden or 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
def maxminlr(stalls_count, users_count): | |
order = users_count.bit_length() - 1 | |
pow_two = 2 ** order | |
k, p = divmod(stalls_count, pow_two * 2) | |
t = users_count | |
if p in range(0, t - pow_two): | |
return (k - 1, k - 1) | |
elif p in range(t - pow_two, t): | |
return (k, k - 1) | |
elif p in range(t, pow_two * 2): | |
return (k, k) | |
def main(): | |
tests_count = int(input()) | |
for i in range(1, tests_count + 1): | |
stalls_count, users_count = input().split() | |
maxlr, minlr = maxminlr(int(stalls_count), int(users_count)) | |
print('Case #{}: {} {}'.format(i, maxlr, minlr)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment