`
SunnyYoona
  • 浏览: 386639 次
社区版块
存档分类
最新评论

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 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;
}



分享到:
评论

相关推荐

    PyPI 官网下载 | ecological-1.2-py3-none-any.whl

    标题中的"PyPI 官网下载 | ecological-1.2-py3-none-any.whl"表明这是一个在Python Package Index(PyPI)上发布的软件包,名为`ecological`,版本为1.2,适用于Python 3环境,且不依赖特定的硬件架构(`none`)和...

    2021年全国大学生程序设计竞赛训练题.doc

    4. Q102:Ecological Bin Packing 5. Q100:考虑 a,b 之间的 2,3,5 倍数联集大小 问题 1:联集读入 在这个问题中,需要读入两个正整数 a,b,输出介于 a,b 之间(包括 a,b)2,3,5 倍数联集大小。 在这个问题中,...

    Pricing Decision of One Leader and Multi-follower Ecological Industry Chain under Incomplete Information

    本文探讨了在不完全信息条件下,单一个领导者和多个追随者的生态工业链中的定价决策问题。在当今社会,传统的生产模式导致了大量资源的开采和能源的消耗,同时在生产和消费过程中,大量的废弃物和污染物被排放到环境...

    A practical guide to ecological modelling

    - **书名**:《生态学建模实践指南》(*A Practical Guide to Ecological Modelling*) - **作者**:Karline Soetaert 和 Peter M.J. Herman - **出版社**:Springer Science+Business Media B.V. - **出版年份**:...

    Applying Graph Theory in Ecological Research

    《Applying Graph Theory in Ecological Research》这本书由Cambridge University Press出版,作者Mark R. T. Dale是不列颠哥伦比亚大学生态系统科学与管理项目的教授,也是区域项目主任。他研究兴趣广泛,包括植物...

    Permanent Ecological 技术白皮书1

    1.0前言摘要2.0 Permanent Ecological 简明概述3.0 Permanent Ecological 核心技术概述3.1 Tendermin

    multivariate analysis of ecological data

    《多变量生态数据分析》一书是为生态学家、学生和研究人员所著,旨在解决他们分析田野观察和实验结果数据的需要,特别适用于那些处理复杂的生态问题的研究者,例如生物群落随环境条件的变化,以及生物群落对实验操作...

    J0246+Ecological+Architecture.pdf

    J0246+Ecological+Architecture

    Permanent Ecological 经济黄皮书1

    1.0前言摘要2.0 Permanent Ecological 简明概述3.0 Permanent Ecological 应用生态概述3.1 云算力轻客户端3.

    Ecological data: design, management, and processing

    生态数据管理中经典的一本书,具有很高的参考价值。 费劲千辛万苦才下载到。呵呵。。。。

    吉布斯采样matlab代码-neurips2019-parameter-elimination:neurips2019参数消除

    吉布斯采样matlab代码论文“粒子吉布斯采样中的参数消除”中的实验代码 该存储库包含本文中所有...birch-vector-borne-disease和birch-ecological model )。 相应的子存储库中提供了有关如何运行每个示例的详细信息。

    Ecological Piffle-开源

    本文将聚焦于一个名为“Ecological Piffle”的开源R库,探讨其在生态学统计分析中的应用与价值。 “Ecological Piffle”是一个专门为生态学家设计的R库,旨在简化生态学统计分析过程,并提供可扩展的函数来实现复杂...

    2022年美赛获奖E类论文_2218144.pdf

    加蓬作为世界领先的木材生产国之一,实行了选择性采伐政策,即每公顷土地上不超过一棵树木被砍伐。然而,无节制的采伐活动可能导致土壤侵蚀加剧、生物多样性减少等一系列环境问题。与此同时,合理利用木材资源不仅...

    Ecological Information-Based Approach:Ecological Information-Based Approach 指标-matlab开发

    这是一个简单的代码,用于计算节点数、总系统吞吐量(TST)、平均互信息(AMI)、条件熵、有效连通性和以矩阵形式表示的基于信息流的网络的有效角色数。 这些计算基于基于生态信息的方法(Ulanowicz 等,2009)。

    地理专业词汇英语翻译

    - "ecological agriculture"即生态农业,强调在农业生产中采用可持续的方法,以保护环境并提高生态系统的健康。 - "ecological amplitude"表示生态幅度,指一个物种或生物群落能在不同环境条件下生存的范围。 - ...

    ecological-stats

    标题“ecological-stats”可能指的是一个关于生态统计的项目或者工具,这通常涉及到对环境数据的收集、分析和可视化。生态统计是应用统计学的方法来研究生物多样性、生态系统功能以及环境变化等领域。在这个项目中,...

    ecological-inference

    pip install git+git://github.com/mggg/ecological-inference.git 示例笔记本 查看中的示例代码,该示例代码显示如何在日期集上运行和调整PyEI中的各种模型。 对于2 x 2的情况,请查看santa_clara_demo.ipynb的...

Global site tag (gtag.js) - Google Analytics