1017 products packed
来源:互联网 发布:java中的锁 编辑:程序博客网 时间:2024/06/11 08:09
1017 Problem R
A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6.
题意:装箱问题,有六种不同大小的箱子,将它们装入另一箱中,需要使用最少的箱子。
思路:装箱过程中,应采取由大到小的原则,大的占一个箱子,小的充分利用剩余空间。
感想:局部最优解,较大的箱子只能占一个大箱,而小的则可使用其他剩余空间,只有在较大箱全部装入后,小箱在放会最大程度上节省空间。
#include<iostream>
#include<algorithm>
using namespace std;
int leave[4]={5,3,1,0};
int main(){
int a[7];
int sum,i;
while(1){
sum=0;
int p=0;
for(i=1;i<=6;i++){ cin>>a[i]; p+=a[i]; }
if(p==0) break;
sum+=a[6]+a[5]+a[4]+(a[3]+3)/4;
int a2=a[4]*5+leave[(a[3]+3)%4];
if(a[2]>a2)
sum+=(a[2]-a2+8)/9;
int a1=sum*36-a[6]*36-a[5]*25-a[4]*16-a[3]*9-a[2]*4;
if(a[1]>a1)
sum+=(a[1]-a1+35)/36;
cout<<sum<<endl;
}
}
- 1017 products packed
- Packed record
- _attribute_((packed))
- __attribute__ ((packed))
- __attribute__ ((packed))
- __attribute__ ((packed))
- _attribute_((packed))
- _attribute_((packed))
- _attribute_((packed))
- _attribute_((packed))
- __attribute__((packed))
- __attribute__((packed))
- __attribute__((packed))
- Packed Record
- _attribute_((packed))
- _attribute_((packed))
- _attribute_((packed))
- __attribute__ ((packed))
- 素数环
- Seven More Languages in Seven Weeks (读书笔记):Julia
- springMVC4(1)角色解析与入门配置实例
- 关于大型网站技术演进的思考(十九)--网站静态化处理—web前端优化—上(11)
- 多线程不能不知道的之线程入门
- 1017 products packed
- android配置selector需要注意的点
- memcached学习笔记1(windows 7 64bit 环境下安装memcached)
- 算法之插入排序
- 进程和线程的区别
- CentOS下Samba文件服务器的安装与配置
- 关于大型网站技术演进的思考(十八)--网站静态化处理—反向代理(10)
- ffmpeg time_base详解
- 关于onTouchEvent跟onInterceptEvent的事件处理