File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
kattis/Suspension Bridges Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ from math import cosh , ceil , log2
2+ d , s = map (int , input ().split ())
3+
4+ # > 0.1 will fail :(
5+ # (Math says it)
6+ tol = 10 ** - 4
7+
8+ def f (epsilon ):
9+ # epsilon = a / (a + s) | in 0, 1
10+ return cosh (d * (1 - epsilon )/ (2 * s * epsilon ))- 1 / epsilon # Equation 1
11+
12+ def l (epsilon ):
13+ return 2 * s * ((1 + epsilon )/ (1 - epsilon ))** 0.5 # Equation 2
14+
15+ left , right = 0 , 1
16+ # Fancy math. On peut juste iterer 50 fois
17+ # d_l/d_epsilon pour savoir tol_epsilon(tol_l)
18+ tol_epsilon = (tol ** 3 ) / (2 * s )
19+ iterations = ceil (log2 (1 / tol_epsilon - 2 ))
20+ # Btw, for bs la taille de l'intervalle est (born_sup - born_inf) / step
21+ # step = 1 pour les entiers.
22+
23+ for _ in range (iterations ):
24+ epsilon = (left + right ) / 2
25+ fl = f (epsilon )
26+ if fl > 0 :
27+ left = epsilon + tol_epsilon
28+ else :
29+ right = epsilon - tol_epsilon
30+
31+ print (l (epsilon ))
You can’t perform that action at this time.
0 commit comments