Ray Chasing

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

요약
축에 나란한 상자 안의 한 점에서 다른 점 방향으로 나아가는 광선이 처음 만나는 변이나 꼭짓점을 구한다.
난이도

쉬움10점 중 3점

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

문제

Ray tracing is becoming very popular in modern video games. You decide to brush up on the topic. After reading a bit of the math behind how it works, you feel the need to get a bit of hands-on experience. So you consider the following simple problem that does not involve any reflections of the ray.

Given a box with sides parallel to the xx- and yy-axes of the Euclidean plane, you emit a ray starting from some point in the interior of the box. Calculate which side of the box is first hit by the ray. If the ray perfectly hits a corner, you should indicate both sides of the box that meet at that corner.

Figure 1: Illustration of the second test case. The ray starting at (0,0)(0,0) and passing through (−3,3)(-3,3) will pass through the top-left corner of the box.

입력

The first line of input consists of four integers X_1X\_1, X_2X\_2, Y_1Y\_1, Y_2Y\_2. These give the coordinates of the sides of the box. The second line contains four integers X_sX\_s, Y_sY\_s, X_rX\_r, Y_rY\_r describing two points X_1\<X_s\<X_2X\_1\<X\_s\<X\_2, Y_1\<Y_s\<Y_2Y\_1\<Y\_s\<Y\_2 and (X_s,Y_s)≠(X_r,Y_r)(X\_s,Y\_s) \ne (X\_r,Y\_r) (i.e. the points are distinct). This indicates the ray starts at point (X_s,Y_s)(X\_s,Y\_s) and travels in the direction that passes through (X_r,Y_r)(X\_r,Y\_r). All integers in the input will lie between −104-10^4 and 10410^4 (inclusive). Note, the point (X_r,Y_r)(X\_r,Y\_r) may lie inside the box, on the boundary of the box, or even outside the box; it merely indicates the direction the ray is travelling.

출력

If the ray does not hit a corner of the box, print the appropriate string left, right, bottom, or top indicating which side was hit by the ray. These correspond to the following ranges of coordinates.

  • The left side is (X_1,y):Y_1≤y≤Y_2\\{(X\_1,y):Y\_1≤y≤Y\_2\\}.
  • The right side is (X_2,y):Y_1≤y≤Y_2\\{(X\_2,y):Y\_1≤y≤Y\_2\\}.
  • The bottom side is (x,Y_1):X_1≤y≤X_2\\{(x,Y\_1):X\_1≤y≤X\_2\\}.
  • The top side is (x,Y_2):X_1≤y≤X_2\\{(x,Y\_2):X\_1≤y≤X\_2\\}.

If the ray hits a corner of the box, output the corresponding hyphenated string indicating which corner was hit: top-left, top-right, bottom-left, or bottom-right.

예제4

  1. 예제 1

    입력
    -2 2 -2 2
    0 0 2 2
    
    예상 출력
    top-right
    
  2. 예제 2

    입력
    -2 2 -2 2
    0 0 -3 3
    
    예상 출력
    top-left
    
  3. 예제 3

    입력
    -2 2 -2 2
    0 0 -1 -2
    
    예상 출력
    bottom
    
  4. 예제 4

    입력
    -10 12 17 24
    -9 23 -7 12
    
    예상 출력
    bottom