HDU 5224 Tom and paper(最小周长)

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper.

Input

In the first line, there is an integer T indicates the number of test cases. In the next T lines, there is only one integer n in every line, indicates the area of paper. 
T<=10,n<= 10^9

Output

For each case, output a integer, indicates the answer.

Sample Input

3
2
7
12

Sample Output

6
16
14

题解:给出面积求最小周长问题,数学问题

AC代码

#include<cstdio>
#include<cmath>
int main()
{
    int t,s,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&s);
        n=(int)sqrt((double) s);
        while(s%n)
            n--;
        n=2*(n+s/n);
    printf("%d\n",n);
    }
return 0;
}
时间: 2024-08-04 12:53:34

HDU 5224 Tom and paper(最小周长)的相关文章

hdu 5224 Tom and paper

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5224 Tom and paper Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper. Input I

HDU 5224 Tom and paper(BestCoder Round #40)

题目链接:Tom and paper 题面: Tom and paper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 679    Accepted Submission(s): 432 Problem Description There is a piece of paper in front of Tom, its length

HDU 3458 Enumerate the Triangles(最小周长三角形)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3548 题意: 给定N个点的坐标求这些点能够成的周长最小的三角形的周长. 分析: 设三角形的三变长分别为,a,b,c;  a<b+c;L=a+b+c; 因此当我们的当前的最小周长如果小于其中一条边的二倍的话 那么很明显有这个边构成的三角形的周长一定大于现在的周长, 我们可以根据这个性质进行减枝. 代码如下: #include <iostream> #include <cstdio>

HDU ACM 5224 Tom and paper 水题+暴力枚举

分析:因为长和宽都是整数,所以枚举判断是不是整数,再取最小的即可. #include<iostream> #include<cmath> using namespace std; int main() { int min; int a,i,T; ios::sync_with_stdio(false); cin>>T; while(T--) { cin>>a; min=1000000000; for(i=1;i<=sqrt(a);i++) if(a%i=

Tom and paper

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5224 题意: 给定一张长方形纸的面积,其边长均为整数,求最小周长. 输入:首行输入案例数T,接下来T行分别输入测试面积n: 输出:单行输出最小周长. 案例: Sample Input 3 2 7 12 Sample Output 6 16 14 分析: 此题,本人也是抱着尝试的态度,没想到竟然AC.矩形面积为长*宽,其中一条短边长定不过面积的平方根值,矩形周长为(长*宽)*2,只需找出(长+宽)的最

c.Tom and paper

Tom and paper Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper. Input In the first line, there is an integer T indicates th

ACM已知面积求最小周长

Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper. Input In the first line, there is an integer T indicates the number of te

HDU5224 Tom and paper(BestCoder Round #40)

Tom and paper Accepts: 464 Submissions: 955 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 Tom面前有一张纸,它的长和宽都是整数.Tom知道这张纸的面积n,他想知道这张纸的周长最小是多少. 输入描述 有多组数据.第一行一个正整数T,表示数据组数.接下来T行,每行一个正整数n,表示纸的面积. T≤10,n≤109 输出描述 对于每

已知矩形面积求最小周长

Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper. Input In the first line, there is an integer T indicates the number of te