UVa 102 Ecological Bin Packing (water ver.)

Source: Internet
Author: User
Tags time limit

102-ecological Bin Packing

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=38

Background

Bin packing, or the placement of objects of certain weights into different bins-subject to certain constraints, was an hist Orically interesting problem. Some bin packing problems are np-complete but are amenable to dynamic programming solutions or to approximately optimal the He Uristic Solutions.

In this problem you are solving a bin packing problem that deals with recycling glass.

The Problem

Recycling glass requires that glass is separated by color into one of three categories:brown glass, green glass, and Clear glass. In this problem you are given three recycling bins, each containing a specified number of brown, green and clear Bottl Es. In order to be recycled, the bottles'll need to is moved so this each bin contains bottles of one color.

The problem is to minimize the number of bottles that are moved. You may assume this only problem be to minimize the number of movements between boxes.

For the purposes of the-problem, each bin has infinite capacity and the constraint are moving the bottles so H bin contains bottles of a single color. The total number of bottles would never exceed 2^31.

The Input

The input consists of a series of lines with each line containing 9 integers. The three integers on a line represent the number of brown, green, and clear bottles (respectively) in bin number 1, The second three represent the number of brown, green and clear bottles (respectively) in Bin number 2, and the last thre e integers represent the number of brown, green, and clear bottles (respectively) in bin number 3. For example, the line 10 15 20 30 12 8 15 8 31

Indicates that there are clear bottles into bin 1, green bottles in Bin 2, and brown bottles in Bin 3.

Integers on a line would be separated by one or more spaces. Your program should process all lines in the input file.

The Output

For each line of input there'll be one line of output indicating what color bottles go in what bin to minimize the Numbe R of bottle movements. You should also print the minimum number of bottle movements.

The output should consist of a string of the three upper case characters ' G ', ' B ', ' C ' (representing the colors green, bro WN, and clear) representing the color associated with each bin.

The "character" of the string represents the color associated with the "the", the second character of the string R Epresents the color associated with the second bin, and the third character represents the color associated with the third Bin.

The integer indicating the minimum number of bottle movements should follow the string.

If more than one order of brown, green, and clear bins yields the minimum number of movements then alphabetically T string representing a minimal configuration should be printed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.