QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 32 MB Puntuación total: 100

#6711. 折叠纸条

Estadísticas

有一条宽度为 1 的纸带,其各部分的宽度相等。在纸带的最左端有一条垂直线。纸带足够柔软,可以向右无限延伸。纸带上的所有点都在同一个平面内。

纸带可以沿某个位置的折痕进行折叠。折叠后,纸带会出现重叠部分,但所有点仍处于同一个平面内(假设纸带厚度为 0)。纸带的水平位置定义如下:最左侧线条的位置为 0,坐标轴沿纸带向右延伸。折痕的位置由 $(a, b)$ 描述,“$a$”是折痕与纸带上边缘交点的水平位置,“$b$”是折痕与纸带下边缘交点的水平位置。因此,折痕是穿过点“$a$”和“$b$”的直线。

折叠方向有两种可能。沿折痕,你可以将左侧部分折叠到右侧部分的前面,或者将左侧部分折叠到右侧部分的后面。一次“折叠” $(a, b, d)$ 包含折痕 $(a, b)$ 和方向“$d$”($0$ 表示将左侧部分折叠到前面,$1$ 表示将左侧部分折叠到后面)。

我们将列出一系列折叠操作 $(a_1, b_1, d_1), (a_2, b_2, d_2), \dots, (a_n, b_n, d_n)$,其中 $a_i \leq a_{i+1}$ 且 $b_i \leq b_{i+1}$ ($1 \leq i < n$),你需要按照此序列折叠纸带。如果在第 $i$ 次折叠后,纸带的折叠部分覆盖了下一条尚未折叠的折痕 $i+1$,且位于纸带的同一侧(即第 $i$ 次折叠和第 $i+1$ 次折叠的方向相同),则称折痕 $i+1$ 为“失败的折叠”,如图 (C) 所示。

编写一个程序来判断折叠序列中是否存在失败的折叠。

输入格式

输入包含多个测试用例。每个测试用例的第一行包含折叠序列中的折叠次数 $n$ ($0 < n \leq 1\,000$)。下一行包含 $3n$ 个实数,表示折叠序列:$a_1$ $b_1$ $d_1$ $a_2$ $b_2$ $d_2$ $\dots$ $a_n$ $b_n$ $d_n$。

输入以一行包含单个 $0$ 结束。

输出格式

对于每个测试用例,输出一行结果。如果序列中存在失败的折叠,输出 "NO" 并紧跟失败折叠的索引编号。如果没有失败的折叠,输出 "YES"。

样例

样例输入 1

3
3 4 0 6 5.5 0 10 10 0
4
3 3 0 5 5 1 7 7 0 8 8 1
0

样例输出 1

NO 3
YES

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.