• POJ1017 添格子


    Packets
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 36708   Accepted: 12227

    Description

    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
    本题说是用贪心,说实在的没感觉到贪心的存在,理解了,顺理成章就写下来啦;

    题意:

    公司有几种盒子 如6*6 6*5 3*3 ....当然,只有一层,我们在这里面放物品,物品的规格也是 6* 6 5*5 .....等,问我们最少需要多少个盒子

    输入:

    每行六个数据,分表代表 1*1 2*2 3*3 4*4 ...等等的数量

    当全为0时结束程序

    解题思路:

    先看6*6  这种的是一对一

          5*5  每个可以剩余1*1的有11个空位

      4*4  里面可以添加2*2 或1*1的

      3*3  里面可以添加2*2 或1 *1

         2*2  和 1*1 在上面添加 剩余的话 再自身添加盒子就行啦

    我的基本思路是,从上向下,每次有剩余的时候,先添加2*2 ,有剩余再添加1*1

    注意事项:

    当每次超出一个6*6的规格时,记住要加1,不然少个盒子

    当每次2*2的剩余盒子没用完时,要先加到1*1上后再 让res2归0,(这个让我错了两次)

    2*2 规格 换算为1*1时 记住是*4.哎,人一急救搞错,如果你的测试不通过,可以检查下

    测试数据:

    58 63 33 3 3 3

    结果 24

    我的代码,有点长,还算好理解吧,里面的res1  res2分别代表本次剩余的可以添加2*2  或1*1的格子数量

    View Code
    #include<stdio.h>
    int main()
    {
        int a1,a2,a3,a4,a5,a6;
        int res,res1,res2,sum;
        while(scanf("%d%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5,&a6))
        {
            if(a1+a2+a3+a4+a5+a6==0)
                break;
            sum=0;
            if(a6>0)
                sum+=a6;
            if(a5>0)
            {
                sum+=a5;
                res=a5*11;
                if(res>a1)
                    a1=0;
                else
                    a1-=res;
            }
            if(a4>0)
            {
                sum+=a4;
                res2=5*a4;
                res1=0;////////
                if(a2<res2)
                {
                    res1=(res2-a2)*4;
                    a2=0;
                }
                else
                {
                    a2-=res2;
                    res1=0;
                }
                if(res1>0&&a1>0)
                {
                    if(a1<res1)
                        a1=0;
                    else
                        a1-=res1;
                }
            }
            if(a3>0)
            {
                if(a3>=4)
                {
                  sum+=a3/4;
                  if(a3%4!=0)
                      sum++;
                }
                else
                    sum++;
                res1=res2=0;///////////***
                if(a3%4!=0)
                {
                    res=a3%4;
                    res2=5-(res-1)*2;
                    res1=8-res;
                    if(a2>0)
                    {
                        if(a2<res2)
                        {
                            res1+=(res2-a2)*4;//////
                            a2=0;
                        }
                        else
                        {
                            a2-=res2;
                        }
                    }
                    if(a1>0)
                    {
                        if(a1<res1)
                        {
                            a1=0;
                        }
                        else
                        {
                            a1-=res1;
                        }
                    }
                }
            }
            if(a2>0)
            {
                if(a2>=9)
                {
                    sum+=a2/9;
                    if(a2%9!=0)
                        sum++;
                }
                else
                    sum++;
                res=a2%9;
                if(res>0)
                {
                    res1=(9-res)*4;
                    if(a1>0)
                    {
                        if(a1<res1)
                            a1=0;
                        else
                            a1-=res1;
                    }
                }
            }
            if(a1>0)
            {
                if(a1>=36)
                {
                    sum+=a1/36;
                    if(a1%36!=0)
                        sum++;
                }
                else
                    sum++;
            }
            printf("%d\n",sum);
        }
        return 0;
    }

    下面是一个超短代码,其实也很好理解,可以当做刷排名用吧,呵呵

    View Code
    #include<stdio.h>
    int main(){
        int n,a,b,c,d,e,f,x,y;
        int u[4]={0,5,3,1};
        while(1){
            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;
            n=d+e+f+(c+3)/4;
            y=5*d+u[c%4];
            if(b>y)
                n+=(b-y+8)/9;
            x=36*n-36*f-25*e-16*d-9*c-4*b;
            if(a>x)
                n+=(a-x+35)/36;
            printf("%d\n",n);
        }
        return 0;
    }
  • 相关阅读:
    大数据记录2
    大数据记录1
    Spark 1.5 to 2.1.X
    存储过程定期删除冗余数据
    spark error Caused by: java.io.NotSerializableException: org.apache.hadoop.hdfs.DistributedFileSystem
    spark sql error mismatched input 'union' expecting { <EOF>,''................................
    spark rdd元素println
    spark模型运行时无法连接摸个excutors异常org.apache.spark.shuffle.FetchFailedException: Failed to connect to xxxx/xx.xx.xx.xx:xxxx
    spark模型error java.lang.IllegalArgumentException: Row length is 0
    被简书恶心到了
  • 原文地址:https://www.cnblogs.com/zibuyu/p/2652731.html
Copyright © 2020-2023  润新知