아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Failing Flagship

시간 제한1초메모리 제한1024 MB

요약
N/E/S/W 약어로 주어진 두 나침반 방향에 대해 첫 방향에서 두 번째로 돌아야 하는 최소 각도를 도 단위로 계산한다.
난이도

보통10점 중 4점

유형
구현, 수학, 기하
정답자
아직 제출이 없습니다

문제

Ahoy! You are sailing towards the next "Boats Are Pretty Cool" convention to sell your latest gadget: a new type of compass.

On a normal compass, it is difficult to read off the precise wind direction. However, your new type of compass lets you read off wind directions to a much higher precision! The display can display strings of at most 10001000 characters.

Unfortunately, you have encountered some bad weather. After a few hours of heavy winds and big waves, you can finally look at your compass again. You read off the wind direction XX you are going and know in which wind direction YY you need to go. However, to make the ship turn you have to enter the degrees of the angle the ship has to make in the control system. What is the smallest turn, in degrees, you have to make to get back on the right course?

Figure F.1: Wind directions

The conversion of a wind direction to degrees goes as follows. The four basic wind directions are N, E, S, and W pointing at 00, 9090, 180180, and 270270 degrees, respectively. There are also four wind directions consisting of two letters: NE, SE, SW, and NW, pointing at 4545, 135135, 225225, and 315315 degrees, respectively.

A wind direction can also consist of k≥3k\geq 3 letters l_1l_2…l_kl\_1l\_2\ldots l\_k. In that case, the last two letters indicate one of the four two-letter wind directions, i.e., l_k−1l_k∈NE,SE,SW,NWl\_{k-1}l\_k \in \\{\text{NE}, \text{SE}, \text{SW}, \text{NW}\\} and the other letters are equal to one of these, i.e., l_i∈l_k−1,l_kl\_i \in \\{l\_{k-1}, l\_k\\} for all i≤k−2i \leq k-2. This wind direction points precisely in the middle of the following two wind directions:

  • wind direction l_2…l_kl\_2\ldots l\_k,
  • the first wind direction of at most k−1k-1 letters you encounter when starting in l_2…l_kl\_2\ldots l\_k and move along the circle towards l_1l\_1.

For example, the wind direction SSSE points in the middle of SSE and S, because S is the first wind direction with at most 3 letters when moving from SSE towards S, as can also been seen in Figure F.1.

입력

The input consists of:

  • One line with two strings XX and YY (1≤∣X∣,∣Y∣≤10001 \leq |X|, |Y| \leq 1000), indicating the wind directions as described above.

출력

Output the smallest turn you have to make to go from direction XX to YY.

Your answer should have an absolute error of at most 10−610^{-6}.

예제3

  1. 예제 1

    입력
    N S
    
    예상 출력
    180
    
  2. 예제 2

    입력
    NNE SSSE
    
    예상 출력
    146.25
    
  3. 예제 3

    입력
    ENE NW
    
    예상 출력
    112.5