UVa 102 Ecological Bin Packing (water ver.)

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, is an historically interesting problem. Some bin packing problems are NP-complete but are amenable to dynamic programming solutions or to approximately optimal heuristic solutions.

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

The Problem

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

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

For the purposes of this problem, each bin has infinite capacity and the only constraint is moving the bottles so that each bin contains bottles of a single color. The total number of bottles will never exceed 2^31.

The Input

The input consists of a series of lines with each line containing 9 integers. The first 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 three 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 20 clear bottles in bin 1, 12 green bottles in bin 2, and 15 brown bottles in bin 3.

Integers on a line will 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 will be one line of output indicating what color bottles go in what bin to minimize the number 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, brown, and clear) representing the color associated with each bin.

The first character of the string represents the color associated with the first bin, the second character of the string represents 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 the alphabetically first string representing a minimal configuration should be printed.

时间: 2024-12-02 19:22:43

UVa 102 Ecological Bin Packing (water ver.)的相关文章

UVA之102 - Ecological Bin Packing

 Ecological Bin Packing  Background Bin packing, or the placement of objects of certain weights into different bins subject to certain constraints, is an historically interesting problem. Some bin packing problems are NP-complete but are amenable to

UVa 10656 Maximum Sum (II) (water ver.)

10656 - Maximum Sum (II) Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1597 In a given a sequence of non-negative integers you will have to find such a

UVa 12640 Largest Sum Game (water ver.)

12640 - Largest Sum Game Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=602&page=show_problem&problem=4388 题目:http://uva.onlinejudge.org/external/126/12640.pdf 主要是读取数据怎么处理. 完整代码: /*0

UVa 10921 Find the Telephone (water ver.)

10921 - Find the Telephone Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1862 In some places is common to remember a phone number associating its digits

UVa 10019 Funny Encryption Method (water ver.)

10019 - Funny Encryption Method Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=960 The Problem History : A student from ITESM Campus Monterrey plays with

UVa 10346 Peter's Smokes (water ver.)

10346 - Peter's Smokes Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1287 Peter has n cigarettes. He smokes them one by one keeping all the butts. Out o

UVa 11498 Division of Nlogonia (water ver.)

11498 - Division of Nlogonia Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2493 The Problem After centuries of hostilities and skirmishes between the fo

UVa 457 Linear Cellular Automata (water ver.)

457 - Linear Cellular Automata Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=398 A biologist is experimenting with DNA modification of bacterial colonie

UVa 11044 Searching for Nessy (water ver.)

11044 - Searching for Nessy Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1985 The Loch Ness Monsteris a mysterious and unidentified animal said to inha