zoukankan      html  css  js  c++  java
  • 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

    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.

    $Tleq 10,nleq {10}^{9}$

    Output

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

    Sample Input

    3
    2
    7
    12

    Sample Output

    6
    16
    14

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<vector>
     7 #include<map>
     8 using std::min;
     9 using std::cin;
    10 using std::cout;
    11 using std::endl;
    12 using std::find;
    13 using std::sort;
    14 using std::map;
    15 using std::pair;
    16 using std::vector;
    17 using std::multimap;
    18 #define pb(e) push_back(e)
    19 #define sz(c) (int)(c).size()
    20 #define mp(a, b) make_pair(a, b)
    21 #define all(c) (c).begin(), (c).end()
    22 #define iter(c) decltype((c).begin())
    23 #define cls(arr,val) memset(arr,val,sizeof(arr))
    24 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    25 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    26 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
    27 const int Max_N = 100010;
    28 const int INF = ~0u >> 1;
    29 typedef unsigned long long ull;
    30 void solve(int n) {
    31     int ans = INF;
    32     for (int i = 1; (ull)i * i <= n; i++) {
    33         if (n % i == 0) ans = min(ans, (i + n / i) << 1);
    34     }
    35     printf("%d
    ", ans);
    36 }
    37 int main() {
    38 #ifdef LOCAL
    39     freopen("in.txt", "r", stdin);
    40     freopen("out.txt", "w+", stdout);
    41 #endif
    42     int t, n;
    43     scanf("%d", &t);
    44     while (t--) {
    45         scanf("%d", &n);
    46         solve(n);
    47     }
    48     return 0;
    49 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    Java Synchronized的用法
    静态方法中不能new内部类的实体对象
    android ViewGroup事件分发机制
    安卓设备通过USB接口读取UVC摄像头权限问题
    android View事件分发机制结论
    函数指针与指针函数以及typedef
    GeoHash
    快速排序,C语言实现
    字符串的几个算法
    ANSI C与GNU C
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4617008.html
Copyright © 2011-2022 走看看