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

源代码:

 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 int main()
 5 {
 6     int T,k;
 7     long n,min;
 8     cin>>T;//案例数
 9     while(T--)
10     {
11         cin>>n;//测试数据
12         min=n+1;//假定min为最小周长的二分之一
13         k=int(sqrt(n)+1);//矩形短边边长测试数据最大值
14         for(int i=2;i<=k;i++)
15             if(n%i==0&&min>((n/i)+i))//比较判别最小周长的二分之一
16                 min=i+n/i;
17         cout<<2*min<<endl;//输出最小周长
18     }
19     return 0;
20 }
时间: 2024-12-22 18:16:33

Tom and paper的相关文章

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

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

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