首页 > 专题系列 > Java解POJ > POJ 3536 Beer Refrigerator [解题报告] Java
2013
11-12

POJ 3536 Beer Refrigerator [解题报告] Java

Beer Refrigerator

问题描述 :

Beer Lovers Club makes regular parties. They hate warm beer, but club’s refrigerator is too small to store enough beer for the whole company. So they decided to order a special super-big beer refrigerator. The new refrigerator should be a parallelepiped a × b × c and store exactly n cubical 1 × 1 × 1 beer boxes (the club has n members). To decrease losses of cold, the total area of the surface of the refrigerator must be as small as possible.

For example, if the capacity of the refrigerator must be 12, the possible variants are:

Dimensions Surface Area
3 × 2 × 2 32
4 × 3 × 1 38
6 × 2 × 1 40
12 × 1 × 1 50

The best variant in this case is 3 × 2 × 2.

Help the beer lovers to find the optimal dimensions of their new refrigerator.

输入:

The input file contains single integer number n (1 ≤ n ≤ 106) — the capacity of the refrigerator. Help the beer lovers to find the optimal dimensions of their new refrigerator.

输出:

Output three integer numbers: a, b and c — the optimal dimensions of the refrigerator. If there are several solutions, output any of them.

样例输入:

#112
#213
#31000000

样例输出:

#13 2 2
#21 13 1
#3100 100 100

解题代码:

//* @author: [email protected]
import java.util.*;
public class Main
{
 public static void main(String[] args)
 {
  Scanner in=new Scanner(System.in);
  while(in.hasNext())
  {
   int a=in.nextInt();
   int x=1,y=1,z=a,m=1,n=1,q=a;
   for(int i=(int)Math.pow(a,1.0/3)+1;i>0;i--)
   {
	if(a%i==0)
	{
         x=i;
	  for(int j=(int)Math.sqrt(a/x)+1;j>0;j--)
	  {
	   if((a/x)%j==0)
	   {
	    y=j;
	    z=a/x/j;
	    if(x*y+y*z+z*x< m*n+n*q+q*m)
	    {
		m=x;
		n=y;
		q=z;
	    }
	    break;
	   }
	  }
	 }
     }
     System.out.println(m+" "+n+" "+q);
   }
 }
}

  1. Often We don’t set up on weblogs, but I would like to condition that this established up really forced me individually to do this! considerably outstanding publish