21572_CowsinaSkyscraper

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

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

Pro.ID

21572

Title

Cows in a Skyscraper

Title链接

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

AC

3

Submit

5

Ratio

60.00%

时间&空间限制

  • Time Limit: 6000/3000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    A little known fact about Bessie and friends is that they love stair climbing races.  A better known fact is that cows really don't like going down stairs.  So after the cows finish racing to the top of their favorite skyscraper, they had a problem.  Refusing to climb back down using the stairs, the cows are forced to use the elevator in order to get back to the ground floor.

    The elevator has a maximum weight capacity of W (1 ≤ W ≤ 100,000,000) pounds and cow i weighs Ci (1 ≤ CiW) pounds.  Please help Bessie figure out how to get all the N (1 ≤ N ≤ 18) of the cows to the ground floor using the least number of elevator rides.  The sum of the weights of the cows on each elevator ride must be no larger than W.

    输入

    多测试。

    * Line 1: N and W separated by a space.

    * Lines 2..1+N: Line i+1 contains the integer Ci, giving the weight of one of the cows.

    输出

    Description

    A little known fact about Bessie and friends is that they love stair climbing races.  A better known fact is that cows really don't like going down stairs.  So after the cows finish racing to the top of their favorite skyscraper, they had a problem.  Refusing to climb back down using the stairs, the cows are forced to use the elevator in order to get back to the ground floor.

    The elevator has a maximum weight capacity of W (1 ≤ W ≤ 100,000,000) pounds and cow i weighs Ci (1 ≤ CiW) pounds.  Please help Bessie figure out how to get all the N (1 ≤ N ≤ 18) of the cows to the ground floor using the least number of elevator rides.  The sum of the weights of the cows on each elevator ride must be no larger than W.

    Input

    多测试。

    * Line 1: N and W separated by a space.

    * Lines 2..1+N: Line i+1 contains the integer Ci, giving the weight of one of the cows.

    Output

    * Line 1: A single integer, R, indicating the minimum number of elevator rides needed.

    * Lines 2..1+R: Each line describes the set of cows taking one of the R trips down the elevator.  Each line starts with an integer giving the number of cows in the set, followed by the indices of the individual cows in the set.

    Sample Input

    4 10
    5
    6
    3
    7

    Sample Output

    3
    2 1 3
    1 2
    1 4

    Hint

    INPUT DETAILS:

    There are four cows weighing 5, 6, 3, and 7 pounds.  The elevator has a maximum weight capacity of 10 pounds.

    OUTPUT DETAILS:

    We can put the cow weighing 3 on the same elevator as any other cow but the other three cows are too heavy to be combined.  For the solution above, elevator ride 1 involves cow #1 and #3, elevator ride 2 involves cow #2, and elevator ride 3 involves cow #4.  Several other solutions are possible for this input.

    Source

    样例输入

    4 10
    5
    6
    3
    7

    样例输出

    3
    2 1 3
    1 2
    1 4

    提示

    INPUT DETAILS:

    There are four cows weighing 5, 6, 3, and 7 pounds.  The elevator has a maximum weight capacity of 10 pounds.

    OUTPUT DETAILS:

    We can put the cow weighing 3 on the same elevator as any other cow but the other three cows are too heavy to be combined.  For the solution above, elevator ride 1 involves cow #1 and #3, elevator ride 2 involves cow #2, and elevator ride 3 involves cow #4.  Several other solutions are possible for this input.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部