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 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≤109

Output

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

Sample Input

3
2
7
12

Sample Output

6
16
14

大意:给你一个n表示一个纸片的面积,长和宽都是整数,问你最小的纸片的周长

orz对于精度水题好讨厌的感觉,,

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int n;
    int T;
    scanf("%d",&T);
    while(T--){
    scanf("%d",&n);
        int ans = 2*(n+1);
        for(int i = 1; i*i <=n;i++){
            if(n % i == 0)
            ans = min(ans,2*(i + n/i));
        }
        printf("%d\n",ans);
    }
    return 0;
}

  

时间: 2024-10-20 22:33:49

BestCoder Round #40 1001——精度——Tom and paper的相关文章

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

BestCoder Round #29 1001 GTY&#39;s math problem

GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description GTY is a GodBull who will get an Au in NOI . To have more time to learn alg

字符串处理 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<

BestCoder Round #2 1001 TIANKENG’s restaurant

不得不说,bastcoder是个hack游戏啊!!! 题意:求最少要多少张椅子才能让所有来的客人有地方坐!! 就是一个区间的处理吧!!!和HDU  1556 我待水似流年,流年待我似水神似!!!! 求的是重叠的区间最大,我们只要标记每个区间会有多少人就可以了!!! 然后在从0到1440分统计就OK了!! AC代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<map> #inc

BestCoder Round #2 1001 (简单处理)

题目链接 题意:给N条信息,每个信息代表有x个人从开始的时间 到 结束的时间在餐厅就餐, 问最少需要多少座位才能满足需要. 分析:由于时间只有24*60 所以把每个时间点放到 数组a中,并标记开始的时间+x, 结束的时间 -x.最后累加比较. 如果时间点太多的时候可以把时间点放到结构体里,排序,然后依次枚举结构体. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <