QOJ.ac

QOJ

Limite de temps : 3.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#15901. 灌溉联锁

Statistiques

两个灌溉合作社共享同一片肥沃的山谷。第一个合作社维护散落在田野中的水泵;第二个合作社监管周围山丘上的蓄水池。每当两个合作社决定各自铺设一根新管道时,这两根管道必须相交——在交点处他们可以安装一个联锁阀门。管道总是连接两个不同水泵或两个不同蓄水池的线段。如果两根管道至少有一个公共点,则认为它们相交(接触和重合的管道也视为相交)。

给你笛卡尔平面上每个水泵和每个蓄水池的精确坐标。对于每个规划方案,确定第一个合作社是否可以选择两个不同的水泵,且第二个合作社可以选择两个不同的蓄水池,使得连接它们的两条直管道相交。如果可行,报告这些水泵和蓄水池的下标;否则声明该项目无法实现。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10^5$) —— 规划方案的数量。

对于每个规划方案:

第一行包含一个整数 $n$ ($2 \le n \le 10^5$) —— 第一个合作社管理的水泵数量。

接下来的 $n$ 行,每行包含两个整数 $x_i$ 和 $y_i$ ($|x_i|, |y_i| \le 10^9$) —— 水泵 $i$ 的笛卡尔坐标。水泵的位置两两不同。

下一行包含一个整数 $m$ ($2 \le m \le 10^5$) —— 第二个合作社管理的蓄水池数量。

接下来的 $m$ 行,每行包含两个整数 $u_j$ 和 $v_j$ ($|u_j|, |v_j| \le 10^9$) —— 蓄水池 $j$ 的笛卡尔坐标。蓄水池的位置两两不同。

没有任何水泵与蓄水池重合。

保证所有规划方案中 $n$ 的总和不超过 $2 \cdot 10^5$,且所有规划方案中 $m$ 的总和不超过 $2 \cdot 10^5$。

输出格式

对于每个规划方案:

如果第一个合作社可以选择两个水泵,且第二个合作社可以选择两个蓄水池,使得连接每对设施的直管道相交,则输出四个整数 $p_1, p_2, r_1, r_2$ —— 所选的两个水泵的下标 ($1 \le p_1, p_2 \le n; p_1 \neq p_2$) 和所选的两个蓄水池的下标 ($1 \le r_1, r_2 \le m; r_1 \neq r_2$)。

如果无法相交,则输出 -1

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

样例

输入样例 1

3
4
0 0
4 0
3 3
1 3
5
-1 1
5 1
2 -1
2 4
6 3
4
0 0
1 0
0 1
1 1
4
5 5
6 5
5 6
6 6
3
0 0
4 0
0 2
3
4 -2
4 2
6 1

输出样例 1

1 4 1 2
-1
1 2 1 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.