装箱问题 (贪心水题)

【题目描述】

    一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为1*1, 2*2, 3*3, 4*4, 5*5, 6*6。这些产品通常使用一个 6*6*h 的长方体包裹包装然后邮寄给客户。因为邮费很贵,所以工厂要想方设法的减小每个订单运送时的包裹数量。

【题目链接】

    http://noi.openjudge.cn/ch0406/19/

【算法】

    由于需要装箱的产品总面积一定,则最优情况是箱子浪费面积最少。6,5,4,3所需包裹数是一定的,然后尽可能满足2,最后在考虑1。细节要注意下,同时码力太弱了。。。唉。。。

【代码】

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int ans;
 4 int a[7],b[4]={0,5,3,1};
 5 int main()
 6 {
 7     while(scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])!=EOF) {
 8         if(!a[1]&&!a[2]&&!a[3]&&!a[4]&&!a[5]&&!a[6]) break;
 9         ans=a[6]+a[5]+a[4]+ceil(a[3]/4.0);
10         int for2=a[4]*5+b[a[3]%4];
11         if(for2<a[2]) ans+=ceil((a[2]-for2)/9.0); //至此,2,3,4,5,6所需箱子数已经确定,故当前还能插入的1的个数可以考虑反面用总面积减去用于其它产品的面积
12         int for1=ans*36-36*a[6]-25*a[5]-16*a[4]-9*a[3]-4*a[2];
13         if(for1<a[1]) ans+=ceil((a[1]-for1)/36.0);
14         printf("%d\n",ans);
15     }
16     return 0;
17 }

原文地址:https://www.cnblogs.com/Willendless/p/9351398.html

时间: 2024-10-19 05:05:17

装箱问题 (贪心水题)的相关文章

LightOJ 1166 Old Sorting 置换群 或 贪心 水题

LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : 2017-07-20 14:45:30 * @FileName: LightOJ 1166 贪心 或 置换群 水题.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.co

HDU1050(贪心水题)

Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan t

hdu 5835 Danganronpa 贪心+水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5835 [题意]有n种礼物,每个有ai个,现在开始给每个人发礼物,每人一个普通礼物和神秘礼物,相邻两人的普通礼物必须不同,每个礼物都可以作为神秘礼物/普通礼物,问最多可以发给多少人. [解题思路] 答案肯定是小于等于sum/2,因为每个小朋友得有2礼物.然而数据太水,sum/2也过了. 我们先考虑平凡的礼物,因为平凡的礼物相邻桌子上不能相同,故先把数量最多的礼物相邻的交替用作平凡的礼物. 如果n=3,

HDU 4334——Trouble——————【贪心&amp;水题】

Trouble Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5388    Accepted Submission(s): 1494 Problem Description Hassan is in trouble. His mathematics teacher has given him a very difficult pro

Educational Codeforces Round 85 B. Middle Class(排序/贪心/水题)

Many years ago Berland was a small country where only nn people lived. Each person had some savings: the ii -th one had aiai burles. The government considered a person as wealthy if he had at least xx burles. To increase the number of wealthy people

uva11389巴士司机问题(贪心水题)

 题目:有n个上午的任务和下午的任务,分配给司机,如果工作总时间超过d,超过的部分要给加班费: 现在让你安排任务,问最小的加班分花费. 思路:将下午的工作时间a按降序排序,晚上时间b按升序排序,不难发现只有将这两组按下标一一配对才能是总花费最小(将任意b[i],b[j]调换位置都不如原来的方案更优) #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include&

poj Yogurt factory (贪心水题)

# include <stdio.h> # include <string.h> # include <algorithm> using namespace std; int main() { int i,n,s; __int64 sum ; int cost[10010],num[10010]; while(~scanf("%d%d",&n,&s)) { for(i=0;i<n;i++) scanf("%d%d&qu

HDU1009_FatMouse&amp;#39; Trade【贪心】【水题】

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 44470    Accepted Submission(s): 14872 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g

HDU1009_FatMouse&#39; Trade【贪心】【水题】

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 44470    Accepted Submission(s): 14872 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g