首页 > 其他 > 详细

c.Tom and paper

时间:2015-07-31 23:21:14      阅读:330      评论:0      收藏:0      [点我收藏+]

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 the number of test cases. In the next T lines, there is only one integer n in every line, indicates the area of paper.         技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享 技术分享  
      
                

Output

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

Sample Input

3
2
7
12
                

Sample Output

6
16
14
 
题目大意:
已知面积,求最小周长。
 
分析:
要想求最小周长要已知一条边。C=2*(a/i+i)或C=2*(1+n)将两个进行比较,输出最小值。
注意:
判断i的范围,想到正方形边长=sqrt(n)
 
代码:
技术分享
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cmath>
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     int T;
10     scanf("%d",&T);
11     while(T--)
12     {
13         int n;
14         scanf("%d",&n);
15         int a,c;        
16         for(int i=1;i<=sqrt(n);i++)
17         {
18             a=2*(n+1);
19             
20             if(n%i==0)
21                 c=2*(n/i+i);
22                 if(c<=a)
23                     a=c;
24         }
25         printf("%d\n",a);
26     }
27     return 0;
28 }
View Code

 

c.Tom and paper

原文:http://www.cnblogs.com/ttmj865/p/4693233.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!