QOJ.ac

QOJ

حد الوقت: 2.5 s حد الذاكرة: 256 MB مجموع النقاط: 100

#3055. 激光切割机

الإحصائيات

Ciel 正在进行木工活。她想用激光切割机在木板上进行切割。

为了简化问题,我们假设木板是一个二维平面。木板上有若干条线段,Ciel 希望沿着这些线段进行切割。每条线段都有一个方向,Ciel 必须沿着这些方向切割这些线段。如果忽略方向,这些线段是连通的,也就是说,线段上的任意两点都可以通过这些线段直接或间接地连接起来。

当激光切割机开启时,它会发射激光照射在木板上的某一点,并沿着其轨迹切割木板。激光初始指向 $(x, y)$。Ciel 可以执行以下两种操作:

  • 开启激光并移动切割机,沿着线段的方向切割(部分)线段,或者
  • 关闭激光并将切割机移动到任意位置。Ciel 不一定需要一次性切完整个线段;她可以在线段上的任意一点开始或停止切割。

Ciel 希望提高效率,因此她想知道一条最短路径,使得激光切割机能够切完所有线段的全部部分,并最终回到初始位置。你的任务是编写一个程序,计算激光切割机移动的总距离的最小值。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 300$),表示线段的数量。下一行包含两个整数 $x$ 和 $y$ ($-1000 \le x, y \le 1000$),表示激光的初始位置 $(x, y)$。接下来的 $n$ 行中,第 $i$ 行包含四个整数 $sx_i, sy_i, tx_i$ 和 $ty_i$ ($-1000 \le sx_i, sy_i, tx_i, ty_i \le 1000$),表示第 $i$ 条线段的端点,且激光切割机可以沿着从 $(sx_i, sy_i)$ 到 $(tx_i, ty_i)$ 的方向切割木板。输入满足以下条件:

对于所有 $i$ ($1 \le i \le n$),$(sx_i, sy_i) \neq (tx_i, ty_i)$。初始点 $(x, y)$ 位于至少一条给定的线段上。对于所有不同的 $i, j$ ($1 \le i, j \le n$),第 $i$ 条线段和第 $j$ 条线段最多共享一个点。

输出格式

输出一行,包含激光切割机切完所有线段并回到初始位置所需移动的总距离的最小值。绝对误差或相对误差应小于 $10^{-6}$。

样例

样例输入 1

3
0 1
0 0 0 1
0 1 0 2
0 2 0 3

样例输出 1

6.0

样例输入 2

2
0 1
0 0 0 2
-1 1 1 1

样例输出 2

6.8284271247461900

样例输入 3

5
0 0
0 0 1 0
1 1 -1 1
-1 1 -1 -1
-1 -1 1 -1
1 -1 1 1

样例输出 3

10.00

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.