10201_MilkMeasuring

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

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

Pro.ID

10201

Title

Milk Measuring

Title链接

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

AC

3

Submit

13

Ratio

23.08%

时间&空间限制

  • Time Limit: 20000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Farmer John must measure Q ( 1 ≤ Q ≤ 20,000 ) quarts of his finest milk and deliver it in one big bottle to a customer. He fills that bottle with exactly the number of quarts that the customer orders.

    Farmer John has always been frugal. He is at the cow hardware store where he must purchase a set of pails with which to measure out Q quarts of milk from his giant milk tank. Since the pails each cost the same amount, your task is to figure out a minimal set of pails Farmer John can purchase in order to fill a bottle with exactly Q quarts of milk. Additionally, since Farmer John has to carry the pails home, given two minimal sets of pails he should choose the "smaller" one as follows: Sort the sets in ascending order. Compare the first pail in each set and choose the set with the smallest pail. If the first pails match, compare the second pails and choose from among those, else continue until the two sets differ. Thus the set {3, 5, 7, 100} should be chosen over {3, 6, 7, 8}.

    To measure out milk, FJ may completely fill a pail from the tank and pour it into the bottle. He can never remove milk from the bottle or pour milk anywhere except into the bottle. With a one-quart pail, FJ would need only one pail to create any number of quarts in a bottle. Other pail combinations are not so convenient.

    Determine the optimally small number of pails to purchase, given the guarantee that at least one solution is possible for all contest input data.

    输入

    Multiple test cases. For each case,

    Line 1:   The single integer Q

    Line 2:   A single integer P ( 1 ≤ P ≤ 100 ) which is the number of pails in the store

    Lines 3..P+2:   Each line contains a single integer pail_value ( 1 ≤ pail_value ≤ 10000 ), the number of quarts a pail holds

    输出

    Description

    Farmer John must measure Q ( 1 ≤ Q ≤ 20,000 ) quarts of his finest milk and deliver it in one big bottle to a customer. He fills that bottle with exactly the number of quarts that the customer orders.

    Farmer John has always been frugal. He is at the cow hardware store where he must purchase a set of pails with which to measure out Q quarts of milk from his giant milk tank. Since the pails each cost the same amount, your task is to figure out a minimal set of pails Farmer John can purchase in order to fill a bottle with exactly Q quarts of milk. Additionally, since Farmer John has to carry the pails home, given two minimal sets of pails he should choose the "smaller" one as follows: Sort the sets in ascending order. Compare the first pail in each set and choose the set with the smallest pail. If the first pails match, compare the second pails and choose from among those, else continue until the two sets differ. Thus the set {3, 5, 7, 100} should be chosen over {3, 6, 7, 8}.

    To measure out milk, FJ may completely fill a pail from the tank and pour it into the bottle. He can never remove milk from the bottle or pour milk anywhere except into the bottle. With a one-quart pail, FJ would need only one pail to create any number of quarts in a bottle. Other pail combinations are not so convenient.

    Determine the optimally small number of pails to purchase, given the guarantee that at least one solution is possible for all contest input data.

    Input

    Multiple test cases. For each case,

    Line 1:   The single integer Q

    Line 2:   A single integer P ( 1 ≤ P ≤ 100 ) which is the number of pails in the store

    Lines 3..P+2:   Each line contains a single integer pail_value ( 1 ≤ pail_value ≤ 10000 ), the number of quarts a pail holds

    Output

    For each case, output a single line of space separated integers that contains:

    • the minimum number of pails required to measure out the desired number of quarts, followed by:

    • a sorted list (from smallest to largest) of the capacity of each of the required pails

    Sample Input

    16
    3
    3
    5
    7

    Sample Output

    2 3 5

    Source

    样例输入

    16
    3
    3
    5
    7

    样例输出

    2 3 5

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部