QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#2522. 自动驾驶汽车

Statistics

一辆自动驾驶车辆 $V$ 在如下图所示的巨型工厂中行驶,工厂内有垂直和水平的道路。道路要么是水平线段,要么是垂直线段。一条垂直道路和一条水平道路最多相交一次。如果它们相交,则它们是正交相交的,即所有交点都是十字路口。线段的端点坐标均为整数。

车辆 $V$ 在 $t=0$ 时从某条道路的一个端点出发,并根据驾驶算法以每秒一个单位的速度移动。$V$ 沿着道路直线行驶,直到遇到两条道路的交点或道路的尽头。如果到达交点,它会在该交点处左转。如果到达道路尽头,它会在该尽头处折返,并继续根据算法移动。即使车辆回到起点,它也会永远移动下去。车辆在道路尽头折返或在交点处左转所需的时间忽略不计。

让我们通过图 A.1(a) 中的例子来解释。车辆的起点是端点 $a$。它首先到达交点 $b$,左转并向端点 $c$ 移动。它在 $c$ 处折返并再次到达 $b$。然后它左转并沿着 $b$ 和 $d$ 之间的部分移动。它到达另一个交点 $d$ 并向 $e$ 左转,依此类推。如图 A.1(b) 所示,由于算法的转向规则,线段的某些部分不会被车辆经过,即使车辆回到起始端点,它也会继续移动。

给定工厂的道路、车辆 $V$ 的起始端点以及一个非负时间 $t$,编写一个程序来计算 $V$ 在时间 $t$ 时的位置坐标 $(x, y)$。

图 A.1 (a) 工厂中的道路。(b) 车辆回到起点。

图 A.2 下面第二个样例测试用例中给出的道路。

输入格式

程序从标准输入读取数据。输入的第一行包含两个整数 $n$ ($2 \le n \le 500$) 和 $t$ ($0 \le t \le 10^9$),其中 $n$ 是道路的数量(即线段的数量),$t$ 是需要输出车辆位置的时间。在接下来的 $n$ 行中,第 $i$ 行包含四个非负整数 $bx_i, by_i, ex_i, ey_i$,表示一条(水平或垂直)线段的两个端点 $(bx_i, by_i)$ 和 $(ex_i, ey_i)$。两条线段最多相交于一点。车辆的起始端点指定为 $(bx_1, by_1)$。所有端点坐标均在 $0$ 到 $10^7$ 之间。没有道路共享端点。

注意:道路线段不一定连通,且所有交点均为十字路口。

输出格式

程序将结果写入标准输出。打印两个整数 $x$ 和 $y$,表示车辆在时间 $t$ 时的坐标 $(x, y)$。

样例

样例输入 1

5 33
4 4 16 4
4 9 14 9
6 11 6 3
11 6 17 6
13 12 13 1

样例输出 1

13 6

样例输入 2

5 70
4 4 16 4
4 9 14 9
6 11 6 3
11 6 17 6
13 12 13 1

样例输出 2

6 6

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.