uVA311包裹包含

本文介绍了一种解决特定ACM竞赛问题的方法,通过优化算法实现高效计算不同大小盒子的装箱数量。该方法采用逐步逼近的方式,考虑了不同尺寸盒子间的组合关系,最终输出能够装下的1x1盒子的最大数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这题本来是个水题,但是我前面坐的是统计前面几个盒子能装下1X1盒子的数量,估计会超LL,我没改成LL,

一直WA,然后我改成一边统计,一边比较,就A了。

这里贴上代码,写的略微复杂:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<set>
#include<map>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cctype>
#include<queue>
#define LL long long
using namespace std;
const int maxn=1e7+10;
const double eps=1e-8;
const int Max=2147483647;
int main()
{
    int a[6];
    while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5])
    {
        if(!a[0]&&!a[1]&&!a[2]&&!a[3]&&!a[4]&&!a[5])
            break;
        int sum=a[5];
       // int tt=0;
            if(a[4])
            {
                sum+=a[4];
                int tem=a[4]*11;
                if(a[0]>=tem)
                    a[0]-=tem;
                else
                    a[0]=0;
            }
            if(a[3])
            {
                sum+=a[3];
                int tem=a[3]*5;
                if(a[1]>=tem)
                    a[1]-=tem;
                else
                {
                   tem=(tem-a[1])*4;
                 if(a[0]>=tem)
                    a[0]-=tem;
                 else
                    a[0]=0;
                    a[1]=0;
                }
            }
            if(a[2])
            {
                sum=sum+a[2]/4;
                int tem=a[2]%4;
                int tt=0;
                if(tem)
                 {
                      sum++;
                if(tem==1)
                {
                    if(a[1]>=5)
                    {
                        a[1]-=5;
                        tt+=7;
                    }
                    else
                    {
                        tt=tt+27-4*a[1];
                        a[1]=0;
                    }
                }
                if(tem==2)
                {
                    if(a[1]>=3)
                    {
                         a[1]-=3;
                         tt+=6;
                    }

                    else
                    {
                        tt=tt+18-4*a[1];
                        a[1]=0;
                    }
                }
                if(tem==3)
                {
                    if(a[1]>=1)
                    {
                        a[1]-=1;
                        tt+=5;
                    }
                    else
                    {
                        tt=tt+9;
                    }
                }
                 if(a[0]>=tt)
                    a[0]-=tt;
                 else
                    a[0]=0;
                  }
            }

            if(a[1])
            {
                sum=sum+a[1]/9;
                int tem=a[1]%9;
                if(tem)
               {
                sum++;
                tem=36-tem*4;
                if(a[0]>=tem)
                    a[0]-=tem;
                 else
                    a[0]=0;
               }
            }
            if(a[0])
            {
                sum=sum+a[0]/36;
                if(a[0]%36)
                    sum++;
            }
        cout<<sum<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值