poj1017装箱问题

用的纯模拟;;

听说有数学解法,稍候google一下:

#include <iostream>
using namespace std;
 
/*装有3*3 的箱子可放2*2的包数 当放1个3*3可以放5个2*2 2个可放3个2*2*/
int cc[4] = {0, 5, 3, 1};
int a, b, c, d, e, f;
int num;
 
int main()
{
    while (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f))
    {
        if (a==0 && b==0 && c==0 && d==0 && e==0 && f==0) break; 
        /* 4*4,5*5,6*6 的无疑每个都需要一个盒子 */
        num = d + e + f + (c+3)/4;/* (c+3)/4 是对于 3*3 的包需要的 6*6 大小的盒子数 */
        int aa, bb;
        bb = 5*d + cc[c%4];
        /* bb 是已有的包里能放多少个2*2的,每个放 4*4 的盒子还可以放 5 个 2*2的 */
        if (b > bb) /* 如果可装2*2的个数小于2*2的总个数新开箱子 每1~9 个开一个新箱子  */
            num += (b-bb+8)/9;
        aa = num*36 - f*36 - e*25 - d*16 - c*9 - b*4;/* 总共剩下可以装1*1箱子的个数 */
        if (a>aa) /* 如果可装1*1的个数小于1*1的总个数新开箱子 每1~36开一个新箱子 */
            num += (a-aa+35)/36;
        printf("%d\n", num);
    }
    return 0;
}


 

# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <string>

int s[7];

int go () {
	int ans = s[6];
	int t, t1, t2;

	ans += s[5];
	t = s[1] / 11;
	if (t >= s[5]) {
		s[1] -= s[5] * 11;
	}
	else {
		s[1] = 0;
	}
	//printf ("the ans is %d\n", ans);


	t = s[2] / 5;
	ans += s[4];
	if (t >= s[4]) {
		s[2] -= s[4] * 5;
	}
	else {
		t1 = s[4] - t;
		t2 = s[2] % 5;
		s[2] = 0;
		s[1] += t2 * 4;
		t = s[1] / 20;
		if (t >= t1) s[1] -= t1 * 20;
		else s[1] = 0;
	}
	//printf ("the ans is %d\n", ans);

	t = s[3] / 4;
	ans += t;
	t = s[3] % 4;
	if(t) {
		++ ans;
		t = 4 - t;
		t1 = t * 2 - 1;
		if(s[2] >= t1) {
			s[2] -= t1;
			t2 = t * 9 - t1 * 4;
			if(s[1] >= t2) s[1] -= t2;
			else s[1] = 0;
		}
		else {
			s[1] += s[2] * 4;
			s[2] = 0;
			t1 = s[1] / (9 * t);
			if (t1) s[1] -= 9 * t;
			else s[1] = 0;
		}
	}
	//printf ("the ans is %d\n", ans);

	t = s[2] / 9;
	ans += t;
	s[1] += (s[2] - t * 9) * 4;
	t = s[1] / 36;
	ans += t;
	if (s[1] % 36) ++ ans;
	printf ("%d\n", ans);
	return ans;
}

int main () {
	while ((scanf("%d %d %d %d %d %d", &s[1], &s[2], &s[3], &s[4], &s[5], &s[6]), s[1] + s[2] + s[3] + s[4] + s[5] + s[6])) {
		go();
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值