QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 512 MB 总分: 100 可 Hack ✓

#16795. 高尔夫时间

统计

Galina 是一名有抱负的高尔夫球手,她把所有的空闲时间都花在了一个迷你高尔夫公园里。她在这个公园里最喜欢的球场是一个矩形,其一条边平行于南北方向,另一条边平行于东西方向。球非常小,可以看作一个质点。

Galina 想要练习一种被称为“推杆(put)”的特定击球技术。在这种击球中,球被放置在球场内的某个位置,并向东北方向击出,获得 $\sqrt{2}$ 英寸/秒的速度。这意味着球开始以每秒向北移动恰好 1 英寸、向东移动恰好 1 英寸的速度运动。

高尔夫公园采用了一种创新技术,消除了所有摩擦力,无论移动了多远距离,球都将继续以初始速度运动。球与球场边界的碰撞将是完全弹性的。真棒!

球场内部有一个池塘,它被表示为一个简单多边形,其边与球场的边平行。如果球接触到池塘,它会立即沉没。

给你一份 Galina 下一次推杆训练课的起点坐标列表。对于每个起点,假设从该位置进行推杆,计算球在落入池塘前将运动多长时间,并确定它落入池塘的具体位置,或者确定球将无限运动下去。

输入格式

第一行包含两个整数 $w$ 和 $h$,表示球场的宽度和高度,单位为英寸($4 \le w, h \le 5 \cdot 10^8$)。建立坐标系的方式使得球场的四个角坐标分别为 $(0, 0)$、$(w, 0)$、$(w, h)$、$(0, h)$,且点 $(1, 1)$ 位于点 $(0, 0)$ 的东北方向。

第二行包含一个整数 $n$,表示多边形的顶点数($4 \le n \le 1000$)。

接下来的 $n$ 行,每行包含两个整数 $x_i$ 和 $y_i$,表示第 $i$ 个顶点的坐标($1 \le x_i \le w - 1$;$1 \le y_i \le h - 1$)。顶点按遍历顺序给出。

所有多边形顶点都是互不相同的,且没有顶点位于多边形的边上。多边形的所有边要么是垂直的($x_i = x_{i+1}$;$x_n = x_1$),要么是水平的($y_i = y_{i+1}$;$y_n = y_1$),并且任意两条边互不相交。

下一行包含一个整数 $t$,表示击球的起点数量($1 \le t \le 100$)。

接下来的 $t$ 行,每行包含两个整数 $\tilde{x}_i$ 和 $\tilde{y}_i$,表示第 $i$ 个起点的坐标($1 \le \tilde{x}_i \le w - 1$;$1 \le \tilde{y}_i \le h - 1$)。没有起点位于池塘内部或其边界上。

注意,所有起点都是相互独立的。特别地,你可以假设在任何时刻球场内都恰好只有一个球。

输出格式

对于每个起点,按照输入的顺序,如果球永远不会沉没,则输出一个整数 $-1$;否则输出三个整数 $\tau$ $x_s$ $y_s$,分别表示球沉没前运动的时间(以秒为单位),以及沉没发生处的坐标($\tau > 0$;$1 \le x_s \le w - 1$;$1 \le y_s \le h - 1$)。点 $(x_s, y_s)$ 必须属于池塘的边界。

样例

输入格式 1

10 8
6
1 4
1 5
3 5
3 6
4 6
4 4
4
2 2
1 7
4 7
7 5

输出格式 1

2 4 4
3 4 6
13 3 4
15 2 4

输入格式 2

6 6
4
2 2
4 2
4 4
2 4
3
5 5
5 2
5 5

输出格式 2

3 4 4
-1
3 4 4

说明

在第一个样例中,球的轨迹如下图所示:

在第二个样例中,起点 1 和 3 重合,而对于起点 2,球永远不会停止:

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.