很水的一道题,在容量为n个 1*1*1 木块的情况下,设置长、快、高,使得表面积最小,直接遍历就行,2个for循环
具体代码如下:
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
const int maxn = 0xffffff;
int main()
{
int cap,a,b,c,n,a1,b1,c1;
int i,j,k,area,sum;
while(cin>>n){
area = maxn;
for(i = 1; i <= sqrt((double)n); i++){
if(n%i == 0){
for(j = 1; j <= n/i; j++){
if(n%(i*j) == 0){
k = n/(i*j);
if(i*j+j*k+i*k < area){
a1 = i;
b1 = j;
c1 = k;
area = i*j+j*k+i*k;
}
}
}
}
}
cout<<a1<<" "<<b1<<" "<<c1<<" "<<endl;
}
return 0;
}