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

时间: 2024-08-16 03:11:55

c.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

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 输出描述 对于每

BestCoder Round #40 1001——精度——Tom and paper

Problem 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 numb

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 pap

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,只需找出(长+宽)的最

bestcode round #40 1001 Tom and paper

问题描述: 已知一个矩形的面积,求最小周长 示例: 12(1*12.3*4),最小周长为(3+4)*2=14 解题分析: #include<iostream> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int main() { int n,T; cin>>T; while(T--) { cin>>n; int ans = 2*(

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=

数据挖掘方面重要会议的最佳paper集合

数据挖掘方面重要会议的最佳paper集合,后续将陆续分析一下内容: 主要有KDD.SIGMOD.VLDB.ICML.SIGIR KDD (Data Mining) 2013 Simple and Deterministic Matrix Sketching Edo Liberty, Yahoo! Research 2012 Searching and Mining Trillions of Time Series Subsequences under Dynamic Time Warping T