UVA10365 Blocks 的题解

UVA10365 Blocks 的题解

UVA传送门

题目大意

给你 n n n 1 × 1 × 1 1\times 1\times 1 1×1×1 的立方体,拼成一个长方体,求这个长方体的表面积最小是多少。

思路

因为已经给出了小正方体的数量,所以,长方体的体积是不变的。

所以暴力枚举长宽高,根据:差小积大的原理,可以证明长宽高相差越近越好。

然后根据长方体表面积公式: S = 2 × ( a × b + a × h + b × h ) S = 2 \times (a \times b + a \times h + b \times h) S=2×(a×b+a×h+b×h)

最后用 min ⁡ \min min 函数取最小值输出即可。

但是需要注意的是只有枚举出来长方形的体积与正方形的总体积一样,才可以更新答案。

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <string>
#include <cstring>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO {
	inline int read() {
		register int x = 0, f = 1;
		register char c = getchar();
		while (c < '0' || c > '9') {
			if(c == '-') f = -1;
			c = getchar();
		}
		while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
		return x * f;
	}
	inline void write(int x) {
		if(x < 0) putchar('-'), x = -x;
		if(x > 9) write(x / 10);
		putchar(x % 10 + '0');
		return;
	}
}
using namespace fastIO;
int main() {
    int c, n, ans;
    cin >> c;
    for (int i = 1; i <= c; i ++) {
        cin >> n; // 输入
        for (int a = 1; a <= n; a ++) { // 枚举长
            if (n % a == 0) {
                for (int b = 1; b <= n; b ++) { // 枚举宽
                    if (n % (a * b) == 0) {
                        int h = n / (a * b); // 高
						if (a * b * h == n) {
						ans = min (ans, 2 * (a * b + a * h + b * h));
                        }
					}
				}
			}
		}
        cout << ans << endl; // 输出
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值