Packets (poj 1017 贪心)
2015-03-06 16:51
423 查看
Language: Default Packets
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. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6*6. Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number of parcels necessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program. Input The input file consists of several lines specifying orders. Each line specifies one order. Orders are described by six integers separated by one space representing successively the number of packets of individual size from the smallest size 1*1 to the biggest size 6*6. The end of the input file is indicated by the line containing six zeros. Output The output file contains one line for each line in the input file. This line contains the minimal number of parcels into which the order from the corresponding line of the input file can be packed. There is no line in the output file corresponding to the last ``null'' line of the input file. Sample Input 0 0 4 0 0 1 7 5 1 0 0 0 0 0 0 0 0 0 Sample Output 2 1 Source Central Europe 1996 |
这些产品通常使用一个 6*6*h 的长方体箱子包装然后邮寄给客户。求需要的盒子的最少数量。
贪心,直接模拟吧。。。把情况都考虑到,写的蛋疼。。。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set> #include <queue> #pragma comment (linker,"/STACK:102400000,102400000") #define maxn 1005 #define MAXN 2005 #define mod 1000000009 #define INF 0x3f3f3f3f #define pi acos(-1.0) #define eps 1e-6 #define lson rt<<1,l,mid #define rson rt<<1|1,mid+1,r #define FRE(i,a,b) for(i = a; i <= b; i++) #define FRL(i,a,b) for(i = a; i < b; i++) #define mem(t, v) memset ((t) , v, sizeof(t)) #define sf(n) scanf("%d", &n) #define sff(a,b) scanf("%d %d", &a, &b) #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c) #define pf printf #define DBG pf("Hi\n") typedef long long ll; using namespace std; int a[7]; bool have() { int i; FRE(i,1,6) if (a[i]) return true; return false; } int main() { int i,j; while (~sf(a[1])) { int ans=0; int flag=1; FRE(i,2,6) sf(a[i]); FRE(i,1,6) if (a[i]) { flag=0; break; } if (flag) break; int x=0,mm; while (have()) { int maxl=6,cnt=36; //maxl盒子剩下的空间能容纳商品的最大边长,cnt盒子的剩余容量 for (i=6;i>=1;i--) //从大的先装 { if (cnt==0) break; //这个盒子没有容量了 if(a[i]&&i<=maxl){ if (i<3&&maxl==3){ //主要是盒子原先装了3*3的之后再装2*2比较麻烦 if (i==2){ if (cnt==27){ //之前已经装了1个3*3 mm=min(5,a[i]); a[i]-=mm; cnt-=mm*4; } else if (cnt==18){ //之前已经装了2个3*3 mm=min(3,a[i]); a[i]-=mm; cnt-=mm*4; } else if(cnt==9){ //之前已经装了3个3*3 mm=min(1,a[i]); a[i]-=mm; cnt-=mm*4; } } else{ mm=min(a[i],cnt); a[i]-=mm; cnt-=mm; } } else{ if (i==3){ mm=min(4,a[i]); a[i]-=mm; cnt-=mm*9; maxl=3; } else if(i>3){ a[i]--; cnt-=i*i; maxl=6-i; } else{ mm=min(a[i],cnt/(i*i)); a[i]-=mm; cnt-=(mm*i*i); } } } } ans++; //盒子数自增 } pf("%d\n",ans); } return 0; } /* 0 0 4 0 0 1 7 5 1 0 0 0 0 0 0 0 0 0 */
相关文章推荐
- POJ 1017 Packets【贪心】
- POJ 1017 Packets(贪心)
- POJ 1017 Packets(贪心)
- POJ 1017Packets(贪心)
- POJ 1017 Packets(贪心)
- Poj 1017 Packets【贪心+细节】
- POJ1017 Packets 【贪心】
- poj 1017 Packets 贪心 盒子放置问题
- POJ 1017 Packets 贪心
- POJ 1017 Packets(贪心)
- POJ 1017 Packets (贪心)
- 【贪心】【POJ-1017】Packets
- Poj 1017 Packets(贪心策略)
- POJ 1017 Packets 贪心
- POJ1017——Packets(贪心)
- Poj 1017 Packets(贪心策略)
- POJ 1017 Packets 贪心
- Poj 1017 Packets(贪心策略)
- poj 1017 Packets【贪心】
- POJ 1017 Packets (贪心)