Compare commits
2 Commits
c78f8ebf61
...
69c8d0f72c
Author | SHA1 | Date |
---|---|---|
setop | 69c8d0f72c | |
setop | 2ae942085d |
|
@ -0,0 +1,24 @@
|
|||
import sys
|
||||
|
||||
en=enumerate
|
||||
|
||||
L = open(0).read().split('\n\n')
|
||||
L = [l.split(':') for l in L]
|
||||
L = [l[1].strip().split('\n') for l in L]
|
||||
L = [list(map(lambda x: tuple(map(int,x.split())),l)) for l in L]
|
||||
S = list(v for s in L[0] for v in s)
|
||||
|
||||
for i,l in en(L[1:]):
|
||||
print(i, l)
|
||||
# map all seads
|
||||
R = []
|
||||
for s in S:
|
||||
ns = None
|
||||
for dst, src, rg in l:
|
||||
if src <= s < src+rg:
|
||||
ns = dst+(s-src)
|
||||
break
|
||||
R.append(ns if ns else s)
|
||||
S = R
|
||||
print(S)
|
||||
print(min(S))
|
|
@ -0,0 +1,56 @@
|
|||
import sys
|
||||
|
||||
en=enumerate
|
||||
|
||||
def r2v(a,l):
|
||||
return (a, a+l-1)
|
||||
|
||||
def v2r(a,b):
|
||||
return (a, b-a+1)
|
||||
|
||||
def intersec(A:tuple, B:tuple) -> list(tuple):
|
||||
a0, l = A
|
||||
b0, m = B
|
||||
a1 = r2v(A)[1]
|
||||
b1 = r2v(B)[1]
|
||||
if b1 < a0 or a1 < b0: # B outside
|
||||
return A
|
||||
if a0 < b0 and b1 < a1:
|
||||
return [v2r(a0,b0-1),B,(b1+1,a1)]
|
||||
if a0 == b0 and b1 < a1:
|
||||
return [B,(b1+1,a1)]
|
||||
|
||||
if a0 < b0 and b1 < a1:
|
||||
return [v2r(a0,b0-1),B,(b1+1,a1)]
|
||||
if a0 < b0 and b1 < a1:
|
||||
return [v2r(a0,b0-1),B,(b1+1,a1)]
|
||||
if a0 < b0 and b1 < a1:
|
||||
return [v2r(a0,b0-1),B,(b1+1,a1)]
|
||||
|
||||
if b0 <= a1 <= b1:
|
||||
return (b0, a1-b0+1)
|
||||
elif a1 > b1:
|
||||
return B
|
||||
return None
|
||||
|
||||
if __name__ == '__main__':
|
||||
L = open(0).read().split('\n\n')
|
||||
L = [l.split(':') for l in L]
|
||||
L = [l[1].strip().split('\n') for l in L]
|
||||
L = [list(map(lambda x: tuple(map(int,x.split())),l)) for l in L]
|
||||
S = list(v for s in L[0] for v in s)
|
||||
S = list(zip(S[0::2],S[1::2])) # list of range (start, length)
|
||||
|
||||
for i,l in en(L[1:]): # for each transformation
|
||||
print(i, l)
|
||||
R = []
|
||||
for s in S: # transform each seed range
|
||||
ns = None # new range
|
||||
for dst, src, rg in l:
|
||||
if src <= s < src+rg:
|
||||
ns = dst+(s-src)
|
||||
break
|
||||
R.append(ns if ns else s)
|
||||
S = R
|
||||
print(S)
|
||||
print(min(S))
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
SAMPLE = [
|
||||
#Time: Distance:
|
||||
(7, 9),
|
||||
(15, 40),
|
||||
(30, 200),
|
||||
|
||||
]
|
||||
|
||||
INPUT = [
|
||||
(40, 219),
|
||||
(81, 1012),
|
||||
(77, 1365),
|
||||
(72, 1089),
|
||||
]
|
||||
|
||||
|
||||
L = SAMPLE
|
||||
L=INPUT
|
||||
R = 1
|
||||
for (t,r) in L: # time, record
|
||||
S = 0
|
||||
for i in range(t): # hold for i
|
||||
v = i # speed in m/s
|
||||
d = v * (t-i)
|
||||
if d > r:
|
||||
S += 1
|
||||
print(S)
|
||||
R *= S
|
||||
print(R)
|
|
@ -0,0 +1,10 @@
|
|||
import sys
|
||||
|
||||
(t,r) = (int(sys.argv[1]), int(sys.argv[2]))
|
||||
|
||||
print(
|
||||
# i : time of charging, between 0 and t
|
||||
# v = i # speed in m/s
|
||||
# d = v * (t-i) # distance
|
||||
sum(i*(t-i) > r for i in range(t))
|
||||
)
|
Loading…
Reference in New Issue