Created
November 24, 2014 11:57
-
-
Save haje01/a28339c7355183955858 to your computer and use it in GitHub Desktop.
손고리즘 - Festival
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
def calc_mavg(prc, ft): | |
mavg = 100 | |
n = len(prc) | |
fs = 0 | |
for start in xrange(0, n - ft + 1): | |
cur = start + ft | |
fs = sum(prc[start:cur]) if fs == 0 else fs - prc[start - 1] + prc[cur - 1] | |
avg = fs / float(cur - start) | |
if avg < mavg: | |
mavg = avg | |
s = fs | |
while cur < n: | |
s += prc[cur] | |
cur += 1 | |
avg = s / float(cur - start) | |
if avg < mavg: | |
mavg = avg | |
return mavg | |
if __name__ == "__main__": | |
c = int(raw_input()) | |
for i in xrange(c): | |
_, l = [int(i) for i in raw_input().strip().split()] | |
prc = [int(i) for i in raw_input().strip().split()] | |
print "%.11f" % calc_mavg(prc, l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment