天天看點

Google 2014校招測試賽 Problem B

the hamjet is a true marvel of aircraft engineering. it is a jet airplane with a single engine so powerful that it burns all of its fuel instantly during takeoff. the hamjet doesn't have any wings because who needs them when the fuselage is made of a special wonderflonium isotope that makes it impervious to harm.

piloting the hamjet is a not a job for your typical, meek-bodied superhero. that's why the hamjet belongs to captain hammer, who is himself impervious to harm. the g-forces that the pilot endures when taking a trip in the hamjet are legen-dary.

the hamjet takes off at an angle of θ degrees up and a speed of v meters per second. vis a fixed value that is determined by the awesome power of the hamjet engine and the capacity of its fuel tank. the destination is d meters away. your job is to program the hamjet's computer to calculate θ given v and d.

fortunately, the hamjet's wondeflonium hull is impervious to air friction. even more fortunately, the hamjet doesn't fly too far or too high, so you can assume that the earth is flat, and that the acceleration due to gravity is a constant 9.8 m/s2 down.

the first line of the input gives the number of test cases, t. t lines follow. each line will contain two positive integers -- v and d.

for each test case, output one line containing "case #x: θ", where x is the case number (starting from 1) and θ is in degrees up from the the horizontal. if there are several possible answers, output the smallest positive one.

an answer will be considered correct if it is within 10-6 of the exact answer, in absolute or relative error. see the faq for an explanation of what that means, and what formats of floating-point numbers we accept.

1 ≤ t ≤ 4500; 1 ≤ v ≤ 300; 1 ≤ d ≤ 10000; it is guaranteed that each test case will be solvable.

解法:抛物線已知重力,初速度和距離,求角度。算算公式就行,在精度的問題上碰了釘子。同樣的公式用python和java得出的結果差0.0000001。重算公式,單步調試,最後還是無法解決。最後直接送出竟然通過了。幸虧沒超過要求的精度範圍。關鍵代碼如下: