Lazy Supermen

Limits 1s, 512 MB

There are two hills in Sonargaon. The heights of them are H1 and H2 meter. The distance between the two hills is D meter. Two supermen are on the top of the two hills. Now they want to meet each other on the ground. But there is a problem. Both of them want to cover as minimum distance as possible. Now your task is to find the distance each of them will cover. Let, one superman will go A1 distance and the other will go A2 distance. You have to minimize A1 , A2 and the summation of (A1 + A2). To minimize A1 and A2 means the absolute difference |A1-A2| will be minimum.

This is a companion discussion topic for the original entry at

I think this problem can’t be solved with python.

Here is my code:

import math

num_test = int(input())
for i in range(num_test):
    h1, h2, distance = map(int, input().split())
    min_h1 = distance**2 + h1**1
    min_h2 = distance**2 + h2**2
    for j in range(distance+1):
        a = math.sqrt(h1**2 + j**2)
        b = math.sqrt(h2**2 + (distance - j)**2)
        if a + b < min_h1 + min_h2:
            min_h1 = float(str.format('{0:.4f}', a))
            min_h2 = float(str.format('{0:.4f}', b))

Maybe… That’s because the H1, H2 and D inputs are not inline… As for C++ it adjusts…