QOJ.ac

QOJ

시간 제한: 1.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#17883. 在平面上奔跑

통계

给你一个由平面上 $n$ 个点组成的集合 $S = \{(a_1, b_1), (a_2, b_2), \dots, (a_n, b_n)\}$。$S$ 中所有点的坐标均为整数。

一个由 $m$ 个二维向量组成的集合 $T = \{(c_1, d_1), (c_2, d_2), \dots, (c_m, d_m)\}$ 被称为 $S$ 的一个优秀集合(good set),如果它满足以下条件:

  1. 存在一个非空的有限平面点序列 $((x_0, y_0), (x_1, y_1), \dots, (x_l, y_l))$,满足:

    • (a) $(x_0, y_0) = (0, 0)$。
    • (b) 对于 $S$ 中的所有点 $p$,存在一个整数 $i$($0 \le i \le l$)使得 $(x_i, y_i) = p$。
    • (c) 对于所有整数 $i$($0 \le i < l$),向量 $(x_{i+1} - x_i, y_{i+1} - y_i)$ 属于 $T$。
  2. 对于所有整数 $i$($1 \le i \le m$),$c_i$ 和 $d_i$ 是介于 $-10^{18}$ 和 $10^{18}$ 之间(含两端)的整数。

求任意一个大小最小的优秀集合。

输入格式

输入包含多组测试数据。第一行包含一个整数 $Q$ —— 测试数据的组数。接下来是每组测试数据的描述。对于每组测试数据:

  • 第一行包含一个整数 $n$ —— $S$ 中点的数量。
  • 接下来的 $n$ 行中,第 $i$ 行包含两个整数 $a_i$ 和 $b_i$ —— $S$ 中每个点的坐标。

输出格式

对于每组测试数据:

  • 设 $T = \{(c_1, d_1), (c_2, d_2), \dots, (c_m, d_m)\}$ 是 $S$ 的一个大小最小的优秀集合。
  • 在第一行输出一个整数 $m$ —— $T$ 中向量的数量。
  • 在接下来的 $m$ 行中,第 $i$ 行输出两个整数 $c_i$ 和 $d_i$ —— 每个向量的坐标。

如果存在多个解,输出其中任意一个即可。

可以证明,在本题的限制下,总是存在一个大小不超过 $10 \times n$ 的 $S$ 的优秀集合。

数据范围

  • $1 \le Q \le 50\,000$
  • 所有测试数据的 $n$ 之和不超过 $10^5$。
  • $2 \le n \le 10^5$
  • $-10^8 \le a_i, b_i \le 10^8$ ($1 \le i \le n$)
  • $(a_i, b_i) \neq (a_j, b_j)$ ($1 \le i < j \le n$)
  • $m \ge 0$
  • $-10^{18} \le c_i, d_i \le 10^{18}$ ($1 \le i \le m$)
  • $(c_i, d_i) \neq (c_j, d_j)$ ($1 \le i < j \le m$)

样例

输入样例 1

2
2
-30 30
-50 50
3
2 1
1 0
4 1

输出样例 1

1
-10 10
2
1 0
1 1

说明

在第一组测试数据中,$T = \{(-10, 10)\}$ 是 $S = \{(-30, 30), (-50, 50)\}$ 的一个大小最小的优秀集合。 我们可以选择序列 $((0, 0), (-10, 10), (-20, 20), \underline{(-30, 30)}, (-40, 40), \underline{(-50, 50)})$。这里,下划线标出的点属于 $S$。

在第二组测试数据中,$T = \{(1, 0), (1, 1)\}$ 是 $S = \{(2, 1), (1, 0), (4, 1)\}$ 的一个大小最小的优秀集合。 我们可以选择序列 $((0, 0), (1, 0), (2, 1), (3, 1), (4, 1))$。

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.