poj 2363 Blocks(暴力)
题目链接:http://poj.org/problem?id=2363
思路分析:由于数据较小,采用暴力搜索法。假设对于矩形边长 1 <= a <= b <= c <= N; 由于 c = N / (a * b), c必须满足条件:为整数且不小于b。
代码如下:
#include <iostream> using namespace std; int main() { int n, min_area; double a, b, c, volume; cin >> n; for ( int i = 0; i < n; ++i ) { cin >> volume; min_area = INT_MAX; for ( a = 1; a <= volume; ++a ) { for ( b = a; b <= volume; ++b ) { c = (double)volume / (a*b); if ( c < b ) break; else if ( c - int(c) == 0.0 ) { int area = ( a*b + a*c + b*c ) * 2; if ( area < min_area ) min_area = area; } } } cout << min_area << endl; } }