UVA之102 - Ecological Bin Packing

22 篇文章 7 订阅

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



### 回答1: bin格式点云数据通常是一种二进制格式,其包含了点云数据的x、y、z坐标、颜色等信息。下载这种格式的点云数据需要注意以下几个步骤: 首先需要找到可供下载的bin格式点云数据源,可以从一些公共库或者私人数据集中寻找。比如,对于地理信息系统(GIS)领域的点云数据,可以从OpenTopography、National Ecological Observatory Network等公共库中找到相关数据。 其次,在下载之前需要确保计算机拥有足够的存储空间来存储这些数据,因为点云数据相对于其他图像数据而言会更加庞大。 然后,在下载的过程中需要注意选择适当的下载工具或者下载方式来保证下载的速度和稳定性。对于大型点云数据的下载,可以考虑使用分块、断点续传等方式来提高下载效率并保证数据完整性。 最后,在下载完成之后,需要认真对下载的数据进行校验和前期处理以确保数据的可用性。这包括将数据存储到合适的位置、选择合适的工具对数据进行清洗和分析、以及将数据转换为其他格式以便于使用等。 总的来说,bin格式点云数据的下载需要细心、认真地进行,并且需要结合后续的数据处理工作来最大程度地发掘数据的潜在价值。 ### 回答2: bin格式是点云数据常用的一种文件格式,它将点云数据以二进制数值的形式存储在文件中。如果你想要下载bin格式点云数据,一种简单的方法是通过网络上的点云数据网站进行下载。 首先,你可以在网站上搜索你需要的点云数据,然后筛选出采用bin格式存储的数据。接下来,你可以点击下载按钮,等待下载完成。 下载完成后,你需要使用点云数据的处理软件进行打开和读取。常见的点云数据处理软件有PCL、CloudCompare等。在打开文件时,需要设置bin格式的文件名和存储格式,一般在读取速度和存储空间之间进行取舍。读取完成后,你可以对点云数据进行各种处理操作,如滤波、配准、分割等。 需要注意的是,bin格式虽然存储速度和占用空间比较小,但是它不具有通用性,不同点云数据采用的存储格式可能存在差别。因此,在使用bin格式点云数据时,需要事先了解文件的存储格式,以便正确读取和使用数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@SmartSi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值