-
-
Save vectorijk/43c5ea40a45af301179d9d87499f3199 to your computer and use it in GitHub Desktop.
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
t = input() | |
for kase in range(1, t+1): | |
n = input() | |
d = {} | |
for i in range(n): | |
raw = raw_input() | |
si = raw.split() | |
st = set() | |
for s in si: | |
st = st.union(set(s)) | |
if len(st) not in d: | |
d[len(st)] = [raw] | |
else: | |
d[len(st)].append(raw) | |
mx = max(d.keys()) | |
# print mx | |
r = sorted(d[mx])[0] | |
# print r | |
print "Case #%d: %s" % (kase, r) |
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
# incomplete | |
T = input() | |
def minPos(H): | |
p = [] | |
mi = 2000 | |
for i in range(1, R+1): | |
for j in range(1, C+1): | |
if H[i][j] < mi: | |
p = [] | |
mi = H[i][j] | |
p.append([i,j]) | |
elif H[i][j] = mi: | |
p.append([i,j]) | |
else: | |
continue | |
return p | |
def bfs(H): | |
Dir = [[-1,0], [1,0], [0,-1],[0,1]] | |
ma = -1 | |
pos = minPos(H) | |
q = list(pos) | |
while len(q) > 0: | |
p = q[i] | |
around = [] | |
for d in Dir: | |
arround.append(H[p[0]+d[0]][p[1]+d[1]]) | |
if min(arround) == 0: | |
q.pop(0) | |
continue | |
elif min(arround) == H[p[0]][p[1]]: | |
for d in Dir: | |
if (H[p[0]+d[0]][p[1]+d[1]] == min(around)): | |
q.append([[p[0]+d[0]],[p[1]+d[1]]]) | |
for kase in range(1, T+1): | |
R, C = map(int, raw_input().split()) | |
H = [[0 for i in range(C+2)]] | |
for j in range(R): | |
tmp = map(int, raw_input().split()) | |
tmp.insert(0, 0) | |
tmp.append(0) | |
H.append(tmp) | |
H.append([0 for i in range(C+2)]) | |
ans = None | |
print "Case #%d: %s" % (kase, ans) |
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
import math | |
def sol(M, C): | |
l = M + 1 | |
lo = -1.0 | |
hi = 1.0 | |
mid = None | |
while math.fabs(lo - hi) > 10e-12: | |
mid = (lo + hi)/2.0 | |
tmp = 0.0 | |
R = 1.0 | |
for i in range(M, 0 , -1): | |
# print R, C[i] | |
tmp += R*(C[i]) | |
R *= (1.0 + mid) | |
tmp += -1.0*R*(C[0]) | |
if tmp < 0.0: | |
hi = mid | |
else: | |
lo = mid | |
return mid | |
t = input() | |
for kase in range(1, t+1): | |
M = input() | |
ans = None | |
C = map(int, raw_input().split()) | |
ans = sol(M, C) | |
print "Case #%d: %.12f" % (kase, ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment