POJ 2363 Blocks

Source: Internet
Author: User

Description

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?
Input

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.
Output

Your program showould 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.
Sample Input

5
9
10
26
27
100
Sample Output

30
34
82
54
130
Given a liquid square N, it can be deformed at Will (also a square) to obtain the minimum surface area.
Set A * B * C = N. We can enumerate A = {1 ........ n}; B = {1 .......... n}; C = {1 .......... n}; returns the smallest value to ANS "N 」;
You can print it directly when ANS "N" is used.
LANGUAGE: C
CODE:
[Html]
# Include <stdio. h>
# Define min (a, B) a <B? A: B
# Define INF 1 <30
Int ans [1001];
Void getans ()
{
Int I, j, k;
For (I = 1; I <1001; I ++) ans [I] = INF;
For (I = 1; I <1001; I ++)
{
For (j = 1; j <1001; j ++)
{
If (I * j> 1000) break;
For (k = 1; k <1001; k ++)
{
If (I * j * k> 1001) break;
Ans [I * j * k] = min (ans [I * j * k], (I * j + j * k + k * I) <1 );
}
}
}
}
Int main ()
{
Int n, cas;
Getans ();
Scanf ("% d", & cas );
While (cas --)
{
Scanf ("% d", & n );
Printf ("% d \ n", ans [n]);
}
Return 0;
}

 


Author: ultimater

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.