QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB

#23517. 电线

Statistiques

在两根电线杆 $A$ 和 $B$ 之间逐条添加电线后,出现了电线相互交叉的情况。由于存在短路的风险,希望移除其中一些电线,使电线之间不再相互交叉。

例如,当电线如图 1 所示连接时,移除连接 $A$ 上位置 $1$ 与 $B$ 上位置 $8$ 的电线、连接 $A$ 上位置 $3$ 与 $B$ 上位置 $9$ 的电线,以及连接 $A$ 上位置 $4$ 与 $B$ 上位置 $1$ 的电线后,剩下的所有电线便不再相互交叉。

problem_23517_f0777293e1b8dd052549110b2894c931.jpg

电线与电线杆的连接位置从上到下依次编号。给定电线的数量以及每条电线在两根电线杆上的连接位置编号,请编写程序,求出为了使剩下的所有电线互不交叉,最少需要移除的电线数量。

输入格式

第一行给出两根电线杆之间的电线数量,为不超过 $100$ 的正整数。

从第二行开始,每行依次给出一条电线在电线杆 $A$ 上的连接位置编号以及在电线杆 $B$ 上的连接位置编号。

位置编号为不超过 $500$ 的正整数,同一位置不能连接两条或更多电线。

输出格式

在第一行输出为了使剩下的所有电线互不交叉,最少需要移除的电线数量。

样例

输入格式 1

8
1 8
3 9
2 2
4 1
6 4
10 10
9 7
7 6

输出格式 1

3

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.