若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1138: Problem D: Blocks

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,933

题目描述

Problem D: Blocks
Donald wishes to send a gift to his new nephew, Fooey. Donald is a bit of a traditionalist, so he has chosen to send a set of N classic baby blocks. Each block is a cube, 1 inch by 1 inch by 1 inch. Donald wants to stack the blocks together into a rectangular solid and wrap them all up in brown paper for shipping. How much brown paper does Donald need?
The first line of input contains C, the number of test cases. For each case there is an additional line containing N, the number of blocks to be shipped. N does not exceed 1000. Your program should produce one line of output per case, giving the minimal area of paper (in square inches) needed to wrap the blocks when they are stacked together.

输入

暂无

输出

暂无

样例输入

5
9
10
26
27
100

样例输出

30
34
82
54
130

参考代码

#include <stdio.h>
int C,N,i,j,k,area,best;
main() 
{
    scanf("%d",&C);
    while (C--) 
    {
        scanf("%d",&N);
        best = 1000*1000*1000;
        for (i=1;i*i*i<=N;i++) 
        {
            for (j=i;i*j*j<=N;j++) 
            {
                if (N%(i*j)) continue;
                k = N/(i*j);
                area = 2*i*j + 2*i*k + 2*j*k;
                if (area < best) best = area;
            }
        }
        printf("%dn",best);
   }
}

解析

暂无

hustoj

发表评论 取消回复

要发表评论,您必须先登录。


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Dreams孤独患者 Skip 原站点
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist