QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100

#13085. 电路

Statistics

在单芯片的多层电路设计中,有许多电子电路(如 CPU、ROM、RAM)需要进行布线。由于某些设计限制,只能使用两条水平线段作为导线。你的任务是找到两条水平线,使得它们共同连接的电路数量尽可能多,从而让电信号能够通过这些电路。

这个问题可以形式化描述如下:平面上有 $n$ 个轴对齐矩形。每个矩形代表芯片上需要布线的一个电路。矩形之间可能会重叠。你需要找到两条水平线,使得这两条线所穿过的矩形总数最大化。如果一条水平线包含矩形的顶边或底边,则称该矩形被这条水平线穿过。如果一个矩形同时被两条线穿过,它在总数中仅被计算一次。

例如,考虑图 A.1 中的 5 个矩形。图 A.1(c) 展示了两条水平线(红色虚线),它们穿过了全部 5 个矩形,而图 A.1(b) 中的两条水平线穿过了 4 个矩形。

图 A.1:(a) 5 个轴对齐矩形。(b) 穿过 4 个矩形的两条水平线。(c) 穿过 5 个矩形的两条水平线。

给定一组轴对齐矩形,编写一个程序来寻找两条水平线,使得这两条线所穿过的矩形总数最大化。

输入格式

程序从标准输入读取数据。第一行包含一个正整数 $n$,表示平面上轴对齐矩形的数量,其中 $3 \le n \le 100,000$。接下来的 $n$ 行,每行包含四个整数 $u_x, u_y, v_x$ 和 $v_y$(满足 $u_x < v_x$ 且 $u_y > v_y$),分别表示轴对齐矩形左上角的 $(u_x, u_y)$ 坐标和右下角的 $(v_x, v_y)$ 坐标,其中 $-10,000,000 \le u_x, u_y, v_x, v_y \le 10,000,000$。

输出格式

程序应写入标准输出。输出仅一行,包含两条水平线所能穿过的矩形的最大总数。

样例

样例输入 1

5
0 13 4 4
2 14 11 9
7 17 12 12
3 5 16 0
5 2 13 1

样例输出 1

5

样例输入 2

5
0 4 4 0
1 3 3 1
5 8 9 4
0 12 4 8
1 11 3 9

样例输出 2

4

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.