问题描述:

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.

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 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.

输出说明:

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

SAMPLEOUTPUT:

BCG 30
CBG 50

思路:

是贪心还是暴力?总之我用的是暴力(),题意是告诉我们3个垃圾桶里3个不同的颜色瓶子数量,然后问我们让每个垃圾桶里只有一种颜色的瓶子的最优移动方式是什么?我在这里的做法就是先用一个二维数组储存6种不同的颜色组合(代表不同的移动方式),然后用一个一维数组s来储存6种不同的移动方式要移动的瓶子数量,取其中的最小值,然后再取对应的二维数组所对应的颜色组合

AC代码:

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{int g[10],b[10],c[10],i,s[10],minmum,temp;char a[6][4]={"BCG","BGC","CBG","CGB","GBC","GCB"};while (cin>>b[1]>>g[1]>>c[1]>>b[2]>>g[2]>>c[2]>>b[3]>>g[3]>>c[3]){temp=0;minmum=g[1]+g[2]+g[3]+c[1]+c[2]+c[3]+b[1]+b[2]+b[3];memset(s,0,sizeof(s));s[0]=g[1]+g[2]+b[2]+b[3]+c[1]+c[3];s[1]=g[1]+g[3]+b[2]+b[3]+c[1]+c[2];s[2]=g[1]+g[2]+b[1]+b[3]+c[2]+c[3];s[3]=g[1]+g[3]+b[1]+b[2]+c[2]+c[3];s[4]=g[2]+g[3]+b[1]+b[3]+c[1]+c[2];s[5]=g[2]+g[3]+b[1]+b[2]+c[1]+c[3];for (i=0;i<6;i++){if (s[i]<minmum){minmum=s[i];temp=i;}if (s[i]==minmum){if (a[i][0]<a[temp][0]){temp=i;minmum=s[i];}if (a[i][0]==a[temp][0]&&a[i][1]<a[temp][1]){temp=i;minmum=s[i];}}}cout<<a[temp]<<' '<<minmum<<endl;}return 0;
}

HDU - 1613 Ecological Bin Packing相关推荐

  1. UVa1149 - Bin Packing

    //UVa1149 - Bin Packing //贪心,背包,乘船问题 #include<iostream> #include<algorithm> using namesp ...

  2. 【论文阅读】(2022)A goal-driven ruin and recreate heuristic for the 2D variable-sized bin packing prob...

    文章目录 一.Abstract 摘要 二.Introduction 介绍 三.Solution representation 解决方案的表示 四.Ruin and recreate heuristic ...

  3. 【算法理论】bin packing 装箱问题

    Bin packing(装箱问题) Problem:给定n件物品和k个箱子,每一个箱子的容量为1,每一件物品的大小w为(0,1),要求使用最少数目的箱子来装上全部的物品. 这个问题是NPC问题,只有a ...

  4. Google OR-Tools(六) 装箱问题 Bin Packing

    本文参考Google OR-Tools官网文档介绍OR-Tools的使用方法. 装箱问题的描述是要将一组给定尺寸的物品放置到具有固定容量的容器中,一般情况下由于容器有容量限制,不可能放入所有物品,那么 ...

  5. OR-Tools:2-包装问题,箱包问题(bin packing)

    OR-Tools 解决的问题类型: Linear optimization Constraint optimization Mixed-integer optimization Bin packing ...

  6. java实现 一维装箱问题_装箱问题(Bin packing problem)

    问题的定义 装箱问题(Bin packing problem),又称集装优化,是一个利用运筹学去解决实际生活的的经典问题.在维基百科的定义如下: In the bin packing problem, ...

  7. 【贪心】Bin Packing

    入门题 A set of n 1-dimensional items have to be packed in identical bins. All bins have exactly the sa ...

  8. B - Bin Packing Problem (线段树+multiset)

    第一个算法用线段树来进行快速查询第一个可以装下item的bin 第二个算法用multiset的二分快速找到能装下item的最小的bin(也就是lower_bound()) 线段树可以对无序的序列实现快 ...

  9. 20行代码AC_ 习题8-1 Bin Packing UVA - 1149(贪心+简单二分解析)

    励志用少的代码做高效表达 题意 给定N个物品的中联L1,背包的容量M,同时要求每个背包最多装两个物品,求至少要多少个背包才能装下所有的物品. 解题过程 第一次接触背包类问题. 最初的思路是降序排序,i ...

最新文章

  1. 韩先培:大规模预训练语言模型是下一代知识图谱吗 | 青源 Talk 第6期
  2. 实现迷你解析器把字符串解析成NestInteger类 Mini Parser
  3. 带Left Join的SQL语句的执行顺序
  4. 爬虫之proxy(代理)
  5. 什么是设计模式(Design Patterns)
  6. AE 新建项目(一)(持续更新,做到哪算哪)
  7. 高并发下的 HashMap 为什么会死循环
  8. Bootstrap3 动态模态对话框
  9. PHP收费事件导致用户流失,PHP秒杀系统方案(解决大流量,高并发)
  10. 【JMX】JMX 远程 连接 The client has been closed
  11. 网页左右怎么划分_UI基础汇总——网页设计规范
  12. xpath抓取html不完全,scrapy的xpath是否取HTML标签的情况分析
  13. OpenDDS简单示例
  14. IDEA 打包 jar 包记录
  15. w10连接远程计算机控制,win10系统教你如何远程控制他人电脑的方法
  16. Java版本微信授权登录(概览版)
  17. IP地址和交换机原理
  18. 周四007欧联杯 佛罗伦萨 VS 门兴[11]
  19. linu {,} 使用
  20. 2020互联网大厂中秋礼盒PK!阿里走情怀,腾讯更复古,最走心的是...(文末有福利)

热门文章

  1. 正则表达式匹配USD格式
  2. SQL的INSERT INTO和INSERT INTO SELECT语句
  3. linux 安装java se,Linux 下安裝 Java SE Development Kit(JDK)並配置環境變量
  4. 常用的连续概率分布汇总
  5. linux系统登录新用户,Linux为新员工创建用户以及配置登录公钥
  6. 超市用监控摄像头多大角的_小门店安装监控?
  7. 74HC14中文资料
  8. 微软必应词典客户端 案例分析
  9. 猫猫学习ios 之第三方登录友盟实现
  10. AI 进军考古学!科学家用深度学习算法发现了近 100 万年前人类用火的证据,登上PNAS...