QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#6255. 传送带

Statistics

你是 Boxing And Processing Company 的一名员工,任务是在公司的一个巨大仓库中分配箱子。在 BAPC Ltd.,箱子通过传送带运输。两条传送带可以通过将一条传送带的内容倾倒在另一条上来合并成一条。另一方面,传送带可以通过分流器(splitter)分成两条,分流器将其输入的一部分发送到第一个输出端,其余部分发送到第二个输出端。通常,你的分流器是可调节的,能够以任何可以想象的比例将输入分配到输出传送带上,但为了削减成本,你的老板订购了廉价的仿制分流器,它们只能以固定的比例 $a : b$ 分配输入。你没有与老板争论你真正需要的是 $c : d$ 分流器,而是决定自己动手制作。

当然,面对节俭的老板,你必须注意成本。你构建的分流器系统不能存在永远无法离开系统的箱子,也不能使用永远接收不到任何箱子的分流器。最后,你使用的 $a : b$ 分流器总数不能太多。

给定比例 $a : b$ 和 $c : d$,请构建一个传送带网络,使用最多 200 个仿制 $a : b$ 分流器,该网络具有一个全局输入传送带和两个全局输出传送带,使得全局输入以 $c : d$ 的比例进行分配。

注意,比例为 $x : y$ 的分流器会将输入箱子的 $\frac{x}{x+y}$ 精确地发送到第一个输出端,并将 $\frac{y}{x+y}$ 精确地发送到第二个输出端。

输入格式

  • 第一行包含两个整数 $1 \le a, b \le 10^9$,且 $a + b \le 10^9$,表示你的仿制分流器的比例 $a : b$。
  • 第二行包含两个整数 $1 \le c, d \le 10^9$,且 $c + d \le 10^9$,表示你所需的分流器的比例 $c : d$。

输出格式

  • 第一行包含一个整数 $1 \le n \le 200$,表示所使用的 $a : b$ 分流器的数量。
  • 接下来 $n$ 行,第 $i$ 行包含两个整数 $-2 \le l_i, r_i < n$。

这里 $l_i$ 是连接到第 $i$ 个分流器左侧输出端的连接对象索引,它接收输入量的 $a/(a + b)$。同样,$r_i$ 是接收第 $i$ 个分流器输入量 $b/(a + b)$ 的连接对象索引。分流器从 0 开始编号。全局输入连接到分流器 0。特殊值 $-1$ 和 $-2$ 分别对应第一个和第二个全局输出,它们需要分别接收全局输入的 $c/(c + d)$ 和 $d/(c + d)$。

注意,你放置的分流器不能使得没有任何箱子能到达它,也不能使得通过它的箱子永远无法到达输出端。

如果存在多种可能的解决方案,你可以输出其中任意一个。

样例

样例输入 1

2 3
3 2

样例输出 1

1
-2 -1

样例输入 2

1 2
3 4

样例输出 2

3
-1 1
2 1
0 -2

样例输入 3

1 2
1 2

样例输出 3

3
-2 1
2 0
1 -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.