zoukankan      html  css  js  c++  java
  • HLG 1513 Containers【暴力枚举】

    Description

    At a container terminal, containers arrive from the hinterland, one by one, by rail, by road,or by small ships. The containers are piled up as they arrive. Then the huge cargo ships arrive, each one capable of carrying thousands of containers. The containers are loaded into the ships that will bring them to far away shores. Or the other way round, containers are brought in over sea, piled up, and transported to the hinterland one by one. Anyway, a huge parking lot is needed, to store the containers waiting for further transportation.
    Building the new container terminal at the mouth of the river was a good choice. But there are disadvantages as well. The ground is very muddy, and building on firm ground would have been substantially cheaper. It will be important to build the parking lot not larger than necessary.

    A container is 40 feet long and 8 feet wide. Containers are stacked, but a stack will be at most five containers high. The stacks are organized in rows. Next to a container stack, and between two container stacks (along the long side of the containers) a space of 2 feet is needed for catching the containers. Next to a row of stacks, and between two stacks (along the short side of the containers) a space of 4 feet is needed for the crane that lifts the containers. All containers are placed in the same direction, as the cranes can not make turns on the parking lot.

    The parking lot should be rectangular. Given the required capacity of the parking lot, what will be the best dimension for the parking lot? In the first place the area should be minimal. The second condition is that the parking lot should be as square as possible.
    Below you see a plan for a parking lot with a capacity of 8 stacks. Two rows of four containers each turns out to be the best solution here, with a total area of 92×42 = 3864.
    The parking lot should be rectangular. Given the required capacity of the parking lot, what will be the best dimension for the parking lot? In the first place the area should be minimal. The second condition is that the parking lot should be as square as possible.
    Below you see a plan for a parking lot with a capacity of 8 stacks. Two rows of four containers each turns out to be the best solution here, with a total area of 92×42 = 3864.

    Input
    On the first line one positive number: the number of testcases, at most 100. After that per
    testcase:
    • A single positive integern(n≤10^12) on a single line: the required capacity (number
    of containers) for the parking lot.
    Output

    Per testcase:
    • A single line, containing the length, width (length≥width) and area of the optimal solution. The optimal solution has the least possible area, and if there are multiple solutions having the same area, the difference length−width should be minimal.

    Use the sample format.

    Sample Input
    6
    1
    15
    22
    29
    36
    43
    Sample Output
    48 X 12 = 576
    48 X 32 = 1536
    52 X 48 = 2496
    92 X 32 = 2944
    92 X 42 = 3864
    136 X 32 = 4352

    题意:最多有5个容器摞在一起,而且每个容器的长为40宽为8.容器之间还有间距长间4宽间2,求给的n个装箱最少占地面积.

    思路:暴力的枚举1----sqrt((n+4)/5)+1;之间的数作为长,求出最少面积.

    代码如下:

    View Code
    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<limits.h> 
    #include<math.h> 
    using namespace std; 
    int main()
    {
        int T;
        long long n, i, j;  
        scanf("%d", &T);
        while(T--)
        {
            scanf("%lld", &n);
            n=(n+4)/5;
            long long minnum=LLONG_MAX, minl, minw; 
            for(i=1; i<=(long long)sqrt(1.0*n)+1; i++)
            {
                if(n%i==0) 
                     j=n/i;
                else
                    j=n/i+1; 
                long long mid=(40*i+4*(i+1))*(8*j+2*(j+1));
                if(mid<minnum)
                {
                    minnum=mid, minl=40*i+4*(i+1), minw=8*j+2*(j+1);
                }
            }
            if(minl<minw)
            {
                long long t=minl; minl=minw; minw=t;
            } 
            printf("%lld X %lld = %lld\n", minl, minw, minnum);
        }
    }                
  • 相关阅读:
    设计模式了解
    三次握手
    网络安全常见术语
    threading.Thread 子线程强制停止
    黑帽SEO入门
    Chrome(谷歌)浏览器永久关闭恢复页面提示框(记录)
    FTP文件夹错误:【打开FTP服务器上的文件夹时发生错误。请检查是否有权限访问该文件夹】
    jenkins启动失败,查看状态提示active(exited)
    jenkins打包vue项目报错-未解决
    jenkins迁移报错处理
  • 原文地址:https://www.cnblogs.com/Hilda/p/2624431.html
Copyright © 2011-2022 走看看