F - Regular Triangle Inside a Rectangle Editorial by Kiri8128


Please refer to the pictures on this tweet (I don’t know how to attach pictures in this page..).

Assume \(A\le B\) without losing generality.

(1) If \(B\) is large enough relative to \(A\), the result is \(\displaystyle\frac{A}{\sin \frac{\pi}{3}}\) . The condition is satisfied when \(A \le B\sin \frac{\pi}{3}\) .

(2) Otherwise, the result is skewed. Let \(r\) be the side of the largest regular triangle, \(\theta\) be the angle shown in the second picture. Then we have the following formulas.

\[r\cos\theta=A\]

\[r\cos(\frac{\pi}{6}-\theta)=B\]

Dividing both sides, we have \(\theta = \arctan\Big(\displaystyle\frac{2B}{A}-\sqrt{3} \Big)\) . With this \(\theta\), the answer is \(\displaystyle\frac{A}{\cos\theta}\) .

In your implementation, you can output the smaller of the results from (1) and the result from (2) for simplicity.

AC Code (PyPy 3)

posted:
last update: