시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB44729125966.240%

문제

Jonas is developing the JUxtaPhone and is tasked with animating the compass needle. The API is simple: the compass needle is currently in some direction (between 0 and 359 degrees, with north being 0, east being 90), and is being animated by giving the degrees to spin it. If the needle is pointing north, and you give the compass an input of 90, it will spin clockwise (positive numbers mean clockwise direction) to stop at east, whereas an input of −45 would spin it counterclockwise to stop at north west.

The compass gives the current direction the phone is pointing and Jonas’ task is to animate the needle taking the shortest path from the current needle direction to the correct direction. Many ifs, moduli, and even an arctan later, he is still not convinced his minimumDistance function is correct; he calls you on the phone.

입력

The first line of input contains an integer n1 (0 ≤ n1 ≤ 359), the current direction of the needle. The second line of input contains an integer n2 (0 ≤ n2 ≤ 359), the correct direction of the needle.

출력

Output the change in direction that would make the needle spin the shortest distance from n1 to n2. A positive change indicates spinning the needle clockwise, and a negative change indicates spinning the needle counter-clockwise. If the two input numbers are diametrically opposed, the needle should travel clockwise. I.e., in this case, output 180 rather than −180.

예제 입력 1

315
45

예제 출력 1

90

예제 입력 2

180
270

예제 출력 2

90

예제 입력 3

45
270

예제 출력 3

-135

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2016 J번

  • 문제를 만든 사람: Pål Grønås Drange