13.2 python cramers rule
This commit is contained in:
@@ -8,23 +8,6 @@ Prize: X=(\d+), Y=(\d+)
|
|||||||
|
|
||||||
|
|
||||||
data = open("input.txt").read().strip().split("\n\n")
|
data = open("input.txt").read().strip().split("\n\n")
|
||||||
data = '''
|
|
||||||
Button A: X+94, Y+34
|
|
||||||
Button B: X+22, Y+67
|
|
||||||
Prize: X=8400, Y=5400
|
|
||||||
|
|
||||||
Button A: X+26, Y+66
|
|
||||||
Button B: X+67, Y+21
|
|
||||||
Prize: X=12748, Y=12176
|
|
||||||
|
|
||||||
Button A: X+17, Y+86
|
|
||||||
Button B: X+84, Y+37
|
|
||||||
Prize: X=7870, Y=6450
|
|
||||||
|
|
||||||
Button A: X+69, Y+23
|
|
||||||
Button B: X+27, Y+71
|
|
||||||
Prize: X=18641, Y=10279
|
|
||||||
'''.strip().split("\n\n")
|
|
||||||
|
|
||||||
data = [tuple(map(int, pattern.match(x).groups())) for x in data]
|
data = [tuple(map(int, pattern.match(x).groups())) for x in data]
|
||||||
|
|
||||||
@@ -43,7 +26,6 @@ def f(data):
|
|||||||
if ya*i+yb*j==yt:
|
if ya*i+yb*j==yt:
|
||||||
s2.add((i, j))
|
s2.add((i, j))
|
||||||
if s1&s2:
|
if s1&s2:
|
||||||
print("@0", n, s1&s2)
|
|
||||||
s += tok(min(s1&s2, key=tok))
|
s += tok(min(s1&s2, key=tok))
|
||||||
return s
|
return s
|
||||||
|
|
||||||
@@ -51,41 +33,15 @@ def f(data):
|
|||||||
def f2(data):
|
def f2(data):
|
||||||
s = 0
|
s = 0
|
||||||
for i, (xa, ya, xb, yb, xt, yt) in enumerate(data):
|
for i, (xa, ya, xb, yb, xt, yt) in enumerate(data):
|
||||||
print(f'@1 {i} {xa=}, {ya=}, {xb=}, {yb=}, {xt=}, {yt=}')
|
xt += 10_000_000_000_000
|
||||||
#xt += 10_000_000_000_000
|
yt += 10000000000000
|
||||||
#yt += 10000000000000
|
d = xa*yb - xb*ya
|
||||||
b = 0
|
da = xt*yb - xb*yt
|
||||||
a = 0
|
db = xa*yt - xt*ya
|
||||||
al = 0
|
if da%d==db%d==0:
|
||||||
ar = max(xt//xa+1, yt//ya+1)
|
a = da//d
|
||||||
while ar-al>1:
|
b = db//d
|
||||||
am = (ar+al)//2
|
s += a*3+b
|
||||||
bl = 0
|
|
||||||
br = max(xt//xb+1, yt//yb+1)
|
|
||||||
f = False
|
|
||||||
while br-bl>1:
|
|
||||||
bm = (bl+br)//2
|
|
||||||
if xa*am+xb*bm>xt and ya*am+yb*bm>xt:
|
|
||||||
br = bm
|
|
||||||
elif xa*am+xb*bm<xt and ya*am+yb*bm<xt:
|
|
||||||
bl = bm
|
|
||||||
elif xa*am+xb*bm==xt and ya*am+yb*bm==xt:
|
|
||||||
f = True
|
|
||||||
b = bm
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
print(al, ar)
|
|
||||||
if f:
|
|
||||||
a = am
|
|
||||||
ar = am
|
|
||||||
else:
|
|
||||||
if a>3*br:
|
|
||||||
al = am
|
|
||||||
else:
|
|
||||||
ar = am
|
|
||||||
print('@end', a, b, a*3+b)
|
|
||||||
s += a*3+b
|
|
||||||
return s
|
return s
|
||||||
print(f(data))
|
print(f(data))
|
||||||
print(f2(data))
|
print(f2(data))
|
||||||
|
|||||||
Reference in New Issue
Block a user