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*(1+n);
        for(int i=1;i*i<=n;i++)
        {
            if(n%i==0)
            {
                ans = min(ans,2*(i + n/i));
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
时间: 2024-08-12 12:44:56

bestcode round #40 1001 Tom and paper的相关文章

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

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

字符串处理 BestCoder Round #43 1001 pog loves szh I

题目传送门 1 /* 2 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 using namespace std; 9 10 typedef long long ll; 11 const int MAXN = 1

暴力 BestCoder Round #41 1001 ZCC loves straight flush

题目传送门 1 /* 2 m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 3 ╰· 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 using namespace std; 11 12 const int MAXN = 1

暴力 BestCoder Round #46 1001 YJC tricks time

题目传送门 1 /* 2 暴力:模拟枚举每一个时间的度数 3 详细解释:http://blog.csdn.net/enjoying_science/article/details/46759085 4 期末考结束第一题,看看题解找找感觉:) 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #include <vector> 10 #include <iostr

贪心 BestCoder Round #39 1001 Delete

题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思路一样 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 #include <algorithm> 11 using

BestCoder Round #1 1001 &amp;&amp; 1002 hdu 4857 4858

hdu 4857 逃生 第一题是拓扑排序,不是按照字典序最小输出,而是要使较小的数排在最前面..赛后弄了好久,才比较明白,我一直以为 反向建图,i从1到n,开始深搜dfs( i ),对i点的边,由小到大继续搜一下,同时标记搜过的数,搜过之后就不再搜,搜到底之后ans[cnt++] = u;这样顺序输出就是答案,后来经过超哥指点,才明白深搜贪心是错的.只有 反向建图,用优先队列把较大的数尽量排在前面,然后反序输出才是正解.. 1 #include<iostream> 2 #include<