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.
Sample Input
1 2 3 4 5 6 7 8 9
5 10 5 20 10 5 10 20 10
Sample Output
BCG 30
CBG 50
【解析】
使用枚举法,一共有六种情况,从中选出最小的一个,如果最小的有相同的,按字母顺序输出第一个。
【代码】
/*********************************
* 日期:2013-9-25
* 作者:SJF0115
* 题号: 102 - Ecological Bin Packing
* 来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=38
* 结果:AC
* 来源:UVA
* 总结:
**********************************/
#include<stdio.h>
char str[6][4] = {"BCG","BGC","CBG","CGB","GBC","GCB"};
int main(){
int count[6];
int B1,B2,B3,C1,C2,C3,G1,G2,G3,min,key;
//freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin);
while(scanf("%d %d %d %d %d %d %d %d %d",&B1,&G1,&C1,&B2,&G2,&C2,&B3,&G3,&C3) != EOF){
count[0] = G1+C1+B2+G2+B3+C3;
count[1] = G1+C1+B2+C2+B3+G3;
count[2] = B1+G1+C2+G2+B3+C3;
count[3] = B1+G1+B2+C2+C3+G3;
count[4] = B1+C1+C2+G2+B3+G3;
count[5] = B1+C1+B2+G2+C3+G3;
min = count[0];
key = 0;
for(int i = 1;i < 6;i++){
if(min > count[i]){
min = count[i];
key = i;
}
}
printf("%s %d\n",str[key],min);
}
return 0;
}
分享到:
相关推荐
This text is written to provide a mathematically sound but accessible and engaging introduction to Bayesian ... It emphasizes the power and usefulness of Bayesian methods in an ecological context.
资源来自pypi官网。 资源全名:ecological-1.2-py3-none-any.whl
不完全信息情况下一主多从生态工业链定价策略分析,于海杰,苏生,生态工业链定价决策对于链条各部分来讲至关重要,但是,生态工业领域的研究却将此忽略。这篇论文研究了不完全信息情况下一主多从
生态效益评价与情景模拟相结合的空间管理决策优化--以三峡库区为例,刘明皓,冯源,揭示土地利用覆被变化时空演变规律,辨识生态安全,对促进土地可持续发展具有十分重要的意义。在借助DYNA-CLUE软件建立城乡用地...
Applying Graph Theory in Ecological Research 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 ...
Applying Graph Theory in Ecological Research-Cambridge University Press(2017).pdf
1.0前言摘要2.0 Permanent Ecological 简明概述3.0 Permanent Ecological 核心技术概述3.1 Tendermin
很好的一本解释生态学建模的书哦。喜不喜欢嘛,大家下载后一看就知道了。
introduction of CANOCO in detail
J0246+Ecological+Architecture
1.0前言摘要2.0 Permanent Ecological 简明概述3.0 Permanent Ecological 应用生态概述3.1 云算力轻客户端3.
生态数据管理中经典的一本书,具有很高的参考价值。 费劲千辛万苦才下载到。呵呵。。。。
ecological-stats
吉布斯采样matlab代码论文“粒子吉布斯采样中的参数消除”中的实验代码 该存储库包含本文中所有...birch-vector-borne-disease和birch-ecological model )。 相应的子存储库中提供了有关如何运行每个示例的详细信息。
这是一个简单的代码,用于计算节点数、总系统吞吐量(TST)、平均互信息(AMI)、条件熵、有效连通性和以矩阵形式表示的基于信息流的网络的有效角色数。 这些计算基于基于生态信息的方法(Ulanowicz 等,2009)。
including PCA、RDA and CCA ecological analysis method
\Multivariate Analysis of Ecological Data Using CANOCO
On Construction of Ecological Englsh Classroom in Junior Middle School.zip
Ecological status in the Ligurian Sea The efect of.pdf有关海岸线变化的文献,英文文献,SCI