#P16132. [ICPC 2018 NAIPC] Probe Droids
[ICPC 2018 NAIPC] Probe Droids
题目描述
After being stationed on Hoth, you’ve decided that this is the worst decision you have ever made. The planet is cold, there is nothing to do, and to make matters worse, the Empire keeps sending probe droids down to see if anyone is hiding on the planet. At least you can do something about the probe droids!
The field near your base is covered with these droids in a uniform fashion. Your base has a turret in the southwest (bottom-left) corner of the field, at location . Each remaining lattice point (points with integer coordinates) on the grid of points contains a droid.
An example grid:
:::align{center}
:::
Note that row 1 is at the bottom, row is at the top, column 1 on the left and column on the right.
Your base is at coordinate , while the droids are at all positive coordinates in the range , excluding of course. Your base has a turret on it facing east, towards higher-number columns in row 1. You’ve programmed the turret to operate in the following way: If a droid is its line of sight, then destroy the droid. Otherwise, rotate counter-clockwise until the turret can see a droid. Keep going until all droids are destroyed.
Your task is to figure out the droid destroyed when the turret executes your algorithm.
输入格式
Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will begin with a line with three integers , (, and cannot both be 1) and (), where the grid has rows and columns, and there will be queries to answer. Each of the next lines will have a single integer (), which is a query for the droid destroyed.
输出格式
Output lines, corresponding to the queries in order. For each query, output two integers and , separated by a single space, which represent the row () and column () of the droid destroyed.
3 5 3
1
14
8
1 2
3 1
3 5