According to this Code Jam problem, I try to made it in one line.
-
-
Save neizod/1872573 to your computer and use it in GitHub Desktop.
Minimum Scalar Product
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
min_scalar = '\n'.join('Case #{0}: {2}'.format(test+1, input(), sum(a * b for a, b in zip(sorted(int(v) for v in input().split()), sorted(int(v) for v in input().split())[::-1]))) for test in range(int(input()))) |
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
min_scalar = '\n'.join( | |
'Case #{0}: {2}'.format( | |
test+1, | |
input(), # from test case, the value describe length has no use in python. | |
sum(a * b for a, b in zip( | |
sorted(int(v) for v in input().split()), | |
sorted(int(v) for v in input().split())[::-1]))) | |
for test in range(int(input()))) |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2012 Nattawut Phetmak <http://about.me/neizod> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
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
{ | |
"name": "minimum_scalar_product", | |
"description": "find minimum scalar product of two vector.", | |
"keywords": [ | |
"math", | |
"codejam" | |
] | |
} |
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
min_scalar = '\n'.join('Case #{0}: {2}'.format(test+1, input(), sum(a * b for a, b in zip(sorted(int(v) for v in input().split()), sorted(int(v) for v in input().split())[::-1]))) for test in range(int(input()))) | |
# stdin: | |
# 2 | |
# 3 | |
# 1 3 -5 | |
# -2 4 1 | |
# 5 | |
# 1 2 3 4 5 | |
# 1 0 1 0 1 | |
expected = '''Case #1: -25 | |
Case #2: 6''' | |
print(expected) | |
print(min_scalar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment