Logo
(追記) (追記ここまで)

32051번 - Billiards 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 (추가 시간 없음) 1024 MB33151076.923%

문제

You are challenging a game with prizes, which is similar to billiards. This game uses a kind of billiard table, several balls of the same size, and a prize coin. The top of the table has a flat rectangular cloth-covered area bounded by elastic bumpers, called cushions. The balls can move on this area. The cushions limit the moves so that the centers of the balls are restricted to stay within a rectangular area of width a and length b, called the movable area.

Let the coordinates of the four corners of the movable area be (0, 0), (a, 0), (a, b), and (0, b). At the start of a game, all the balls and the coin are placed on the table so that their centers are at distinct inner lattice points on the movable area, that is, not on its boundaries. As the balls and the coin are small enough, they do not touch each other unless a ball goes toward the center of another ball or the coin.

The challenger chooses one of the balls, and strikes it with a cue to the direction with an angle of 45 degrees to the edges of the boundary of the movable area. The direction is such that both x- and y-coordinates increase. The struck ball will move straight until it reaches a boundary of the movable area, hits another ball, or drops into one of the holes placed at four corners. When the ball reaches a boundary, it bounces on the cushion at the reflection angle equal to its incident angle and continues its straight move. When it hits another ball or drops into a corner hole, the game is over. If it hits the coin before hitting another ball or dropping into a hole, the challenger will win the coin.

Which ball should you strike to win the coin? You want to know all the balls bringing you the coin.

Figure F-1 depicts the first and the second datasets of Sample Input.

Figure F-1: The first and the second datasets of Sample Input

For the first dataset, when the ball No. 2 is struck, it goes directly toward the coin. The ball No. 4 hits the coin after bouncing on the right-side cushion. As the ball No. 1 hits the ball No. 2, and the ball No. 3 drops in the upper right hole, striking them will not be awarded a coin.

For the second dataset, when the only ball No. 1 is struck, after bouncing on the cushions 5 times, it will pass through its original position, and then after bouncing twice more, it reaches the coin.

입력

The input consists of multiple datasets, each in the following format.

a b x y n

x1 y1

xn yn

The first line has five integers. a and b are the width and the length of the movable area, respectively, satisfying 2 ≤ a ≤ 106 and 2 ≤ b ≤ 106. x and y give the coordinates (x, y) of the position of the coin, satisfying 1 ≤ x < a and 1 ≤ y < b. n is the number of balls, satisfying 1 ≤ n ≤ 105.

The balls are numbered from 1 to n, and the i-th line in the following n lines has the coordinates of the ball i. The line contains two integers xi and yi meaning that the coordinates of the center of the ball i are (xi, yi). They satisfy 1 ≤ xi < a and 1 ≤ yi < b. The positions of the coin and all the balls are mutually different.

The end of the input is indicated by a line consisting of five zeros. The number of datasets does not exceed 50. The sum of n of all the datasets does not exceed 5×105.

출력

For each dataset, output in a line all the ball numbers that you should strike to win the coin, separated by a single space. The ball numbers should be in ascending order. When there are no such balls, output "No" in one line.

제한

예제 입력 1

6 6 4 4 4
2 2
3 3
5 5
5 1
4 5 2 2 1
3 3
4 5 1 4 3
1 2
3 4
3 2
0 0 0 0 0

예제 출력 1

2 4
1
No

힌트

출처

ICPC > Regionals > Asia Pacific > Japan > Japan Domestic Contest > 2024 Japan Domestic Contest F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /