Conveyor Belts
Time limit1sMemory limit512 MB
Build a belt network of at most 200 fixed a:b splitters that divides one global input into c:d between the two outputs, given a, b, c, and d.
- Level
Hard8 of 10
- Topics
- Math, Number theory, Recursion
- Solved
- No attempts yet
Problem
You work as an employee of the Boxing And Processing Company and must distribute boxes in one of the company's enormous warehouses. At BAPC Ltd., boxes travel on conveyor belts. Two belts can be merged into one by letting one drop its contents onto the other. A belt can also be split into two with a splitter, which sends a fixed portion of its input to its first output and the rest to its second output.
Adjustable splitters can divide their input in any ratio. To cut costs, your boss ordered cheap knock-off splitters that only divide their input in a fixed ratio . You need splitters, but instead of arguing with the boss, you decide to build them yourself.
You must watch your costs. The system cannot have boxes that never leave it, and it cannot use splitters that never receive any boxes. You also cannot use too many splitters in total.
Given the ratios and , construct a network of belts and at most 200 knock-off splitters. The network has a single global input belt and two global output belts, and the global input is distributed in the ratio .
A splitter with ratio sends exactly of its incoming boxes to the first output and exactly to the second output.
Input
The first line contains two integers and with and , the ratio of the knock-off splitter.
The second line contains two integers and with and , the desired ratio.
Output
The first line contains an integer with , the number of splitters used.
Then follow lines. The -th line contains two integers and with . Here is the splitter connected to the left output of the -th splitter, which receives of its input. Similarly, is the splitter receiving of its input. Splitters are indexed from 0. The global input is connected to splitter 0. The values and stand for the first and second global output, which must receive and of the global input.
A splitter cannot be placed where no box reaches it, and it cannot be placed where a box passing through it never reaches an output. If several solutions exist, any one is accepted.