博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2363 Blocks(我的水题之路——立方体体积和表面积,暴力)
阅读量:4069 次
发布时间:2019-05-25

本文共 1983 字,大约阅读时间需要 6 分钟。

Blocks
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5908   Accepted: 2816

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 should 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

59102627100

Sample Output

30348254130

Source

给出一个长方体的体积(以1的整数为单位),求这个体积的长方体的表面积的最小值。
一开始拿到这个题目,倒是一点思路也没有,这个就是将每个数字的所有的素因子组合成3个数,然后用这3个数计算出组成的长方体的表面积,这样复杂的组合是比较难进行的,不过之后看了一下数据范围最多是有1000,所以觉得可以直接暴力求解。对于体积为v的长方体的三条边a,b,c,对于a和b进行枚举,得到c = v/a/b,同时保证a/b/c均可以整除v,且a * b * c == v ,之后计算出面积,取最小值输出。
代码(1AC):
#include 
#include
#include
int getarea(int a, int b, int c){ return 2 * (a * b + b * c + a * c);}int main(void){ int a, b, c; int area, v, tmp; int ii, casenum; scanf("%d", &casenum); for (ii = 0; ii < casenum; ii++){ scanf("%d", &v); area = 1000000; for (a = 1; a <= sqrt(v); a++){ if (v % a == 0){ for (b = a; b <= sqrt(v); b++){ if (v % b == 0){ c = v / a / b; if (v % c == 0 && a * b * c == v){ tmp = getarea(a, b, c); if (tmp < area){ area = tmp; } } } } } } printf("%d\n", area); } return 0;}

转载地址:http://jooji.baihongyu.com/

你可能感兴趣的文章
【数据结构周周练】003顺序栈与链栈
查看>>
C++类、结构体、函数、变量等命名规则详解
查看>>
C++ goto语句详解
查看>>
【数据结构周周练】008 二叉树的链式创建及测试
查看>>
《软件体系结构》 第九章 软件体系结构评估
查看>>
《软件体系结构》 第十章 软件产品线体系结构
查看>>
《软件过程管理》 第六章 软件过程的项目管理
查看>>
《软件过程管理》 第九章 软件过程的评估和改进
查看>>
《软件过程管理》 第八章 软件过程集成管理
查看>>
分治法 动态规划法 贪心法 回溯法 小结
查看>>
《软件体系结构》 练习题
查看>>
《数据库系统概论》 第一章 绪论
查看>>
《数据库系统概论》 第二章 关系数据库
查看>>
《数据库系统概论》 第三章 关系数据库标准语言SQL
查看>>
SQL语句(二)查询语句
查看>>
SQL语句(六) 自主存取控制
查看>>
《计算机网络》第五章 运输层 ——TCP和UDP 可靠传输原理 TCP流量控制 拥塞控制 连接管理
查看>>
堆排序完整版,含注释
查看>>
二叉树深度优先遍历和广度优先遍历
查看>>
生产者消费者模型,循环队列实现
查看>>