21003_Cog-Wheels

2022-5-16 18:18| 发布者: Hocassian| 查看: 50| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504745507400-Problem List-采集的数据-后羿采集器.html

Pro.ID

21003

Title

Cog-Wheels

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21003

AC

0

Submit

1281

Ratio

0.00%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 3/32768 K (Java/Others)
  • 描述

    Your little sister got a new mechanical building kit, which includes many cog-wheels of different sizes.

    She started building gears with different ratios, but soon she noticed that there were some ratios which were quite difficult to realize, and some others she couldn't realize at all. Since the most intelligent being in your family is your computer (as you have always been claiming), now it has to figure out which ratios are achievable.

    There you are! That's the punishment for bragging about your computer. Now, you must write a program that will do the job: your sister tells you the sizes of the cog-wheels (the numbers of cogs they have) in her kit. Then, she tells you the ratios of the gears she would like to build. Your computer has to decide whether this is possible and, if so, determine how to connect the wheels to obtain the ratio.

    Here is an example: let's assume there are cog-wheels with 6, 12, and 30 cogs. Your sister wants to realize a gear of ratio 4 : 5. One possible solution is the following:

    The picture shows a complete gear of ratio 4 : 5. Four wheels are used: c1 with 12 cogs, d1 with 6 cogs, c2 with 12 cogs, and d2 with 30 cogs. Note that d1 and c2 share one axis. In this configuration, if c1 turns once, d2 will make 4/5 of a rotation.

    On the other hand, no gear of ratio 1 : 6 can be realized using the cog-wheels your sister has.
    The picture above can be written as 12 : 6; 12 : 30. Each transmission is written as c : d, where c and d denote the number of cogs of the two wheels. A list of transitions c1 : d1, c2 : d2, ... , cm : dm means that the second wheel of each transition is on the same axis as the first one of the next transition (di and ci+1 share one axis for 1 ≤ i < m). For those of you who are not good at mechanics: the ratio realized by this gear i

    输入

    The input file contains the descriptions of several sets of cog-wheels, each one followed by a list of ratios to be realized.

    A set of cog-wheels is described by one line starting with the number n of sizes of cog-wheels (1 ≤ n ≤ 20). The rest of the line will consist of n numbers a1, ... , an, the numbers of cogs on the wheels. There will always be at least 5 and at most 100 cogs per wheel. You may assume that your sister has an infinite supply of wheels of each size.

    In your sister's building kit (and thus, in the input file), the number of cogs on every wheel is divisible by the number of cogs on the smallest wheel in the kit.

    The line describing the set of cog-wheels is followed by a list of ratios to be realized. Each ratio to be realized is given by one line containing two numbers aj and bj (1 ≤ aj ,bj ≤ 10000, aj ≠ bj), meaning aj : bj . The line "0 0" marks the end of that list.

    At the end of the input file, there will be a line containing only a zero (instead of the number of cogwheels of the next set).

    输出

    Description

    Your little sister got a new mechanical building kit, which includes many cog-wheels of different sizes.

    She started building gears with different ratios, but soon she noticed that there were some ratios which were quite difficult to realize, and some others she couldn't realize at all. Since the most intelligent being in your family is your computer (as you have always been claiming), now it has to figure out which ratios are achievable.

    There you are! That's the punishment for bragging about your computer. Now, you must write a program that will do the job: your sister tells you the sizes of the cog-wheels (the numbers of cogs they have) in her kit. Then, she tells you the ratios of the gears she would like to build. Your computer has to decide whether this is possible and, if so, determine how to connect the wheels to obtain the ratio.

    Here is an example: let's assume there are cog-wheels with 6, 12, and 30 cogs. Your sister wants to realize a gear of ratio 4 : 5. One possible solution is the following:

    The picture shows a complete gear of ratio 4 : 5. Four wheels are used: c1 with 12 cogs, d1 with 6 cogs, c2 with 12 cogs, and d2 with 30 cogs. Note that d1 and c2 share one axis. In this configuration, if c1 turns once, d2 will make 4/5 of a rotation.

    On the other hand, no gear of ratio 1 : 6 can be realized using the cog-wheels your sister has.
    The picture above can be written as 12 : 6; 12 : 30. Each transmission is written as c : d, where c and d denote the number of cogs of the two wheels. A list of transitions c1 : d1, c2 : d2, ... , cm : dm means that the second wheel of each transition is on the same axis as the first one of the next transition (di and ci+1 share one axis for 1 ≤ i < m). For those of you who are not good at mechanics: the ratio realized by this gear i

    Input

    The input file contains the descriptions of several sets of cog-wheels, each one followed by a list of ratios to be realized.

    A set of cog-wheels is described by one line starting with the number n of sizes of cog-wheels (1 ≤ n ≤ 20). The rest of the line will consist of n numbers a1, ... , an, the numbers of cogs on the wheels. There will always be at least 5 and at most 100 cogs per wheel. You may assume that your sister has an infinite supply of wheels of each size.

    In your sister's building kit (and thus, in the input file), the number of cogs on every wheel is divisible by the number of cogs on the smallest wheel in the kit.

    The line describing the set of cog-wheels is followed by a list of ratios to be realized. Each ratio to be realized is given by one line containing two numbers aj and bj (1 ≤ aj ,bj ≤ 10000, aj ≠ bj), meaning aj : bj . The line "0 0" marks the end of that list.

    At the end of the input file, there will be a line containing only a zero (instead of the number of cogwheels of the next set).

    Output

    Output one section for each set of cog-wheels. The sections should start with the line "Set #k" where k is the number of the set.

    Then, output the results for the ratios from the test set. Output exactly one line for each ratio. Each of these lines should start with "Ratio aj:bj:", followed either by "Impossible" if the ratio cannot be realized with the given set of cog-wheels, or a description of a gear which realizes the ratio. This description has to be in the notation described above: a blank-separated list of transitions, each transition having the form "ci:di".

    The gear does not need to be the smallest possible; we guarantee that if there is a solution then there is a solution using at most 10000 transitions. Any solution with at most that many transitions is an acceptable answer.

    Every section should be followed by a blank line.
    Sample Input

    3 6 12 30
    4 5
    1 6
    0 0
    0

    Sample Output

    Set #1
    Ratio 4:5: 12:30 12:6
    Ratio 1:6: Impossible

    Source

    样例输入

    3 6 12 30
    4 5
    1 6
    0 0
    0

    样例输出

    Set #1
    Ratio 4:5: 12:30 12:6
    Ratio 1:6: Impossible

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部