zoukankan      html  css  js  c++  java
  • codeforces 859B

     Lazy Security Guard

     Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite.

    Input
    Input will consist of a single integer N (1 ≤ N ≤ 106), the number of city blocks that must be enclosed by the route.


    Output
    Print the minimum perimeter that can be achieved.


    Example
    Input
    4
    Output
    8
    Input
    11
    Output
    14
    Input
    22
    Output
    20

    Note
    Here are some possible shapes for the examples:




    题意:给出正方形的个数,拼到一起能够拼出最少的边;
    思路:找规律,打表。
    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<string.h>
    #include<math.h>
    using namespace std;
    long long a[1100000];
    int main()
    {
        int n;
        a[0]=0;
        a[1]=4;
        a[2]=6;
        long long t=8;
        long long q=2;
        int i=3;
        while(1)
        {
            for(int j=0; j<q; j++)
            {
                a[i++]=t;
            }
            if(i>1000010)
                break;
            t+=2;
            for(int j=0; j<q; j++)
            {
                a[i++]=t;
            }
            q++;
            t+=2;
            if(i>1000010)
                break;
        }
    //    for(int i=1;i<=25;i++)
    //        cout<<a[i]<<endl;
        while(~scanf("%d",&n))
        {
    
            cout<<a[n]<<endl;
        }
    }
    










  • 相关阅读:
    html meta标签使用总结
    HTTP与HTTPS握手的那些事
    JS windows.open打开窗口并居中
    什么是响应式web设计
    phpstorm2017 激活方法
    php与mysql 绑定变量和预定义处理
    php和mysql数据库防SQL注入的有效解决办法
    如何高效率的写一个不会重复出现的随机数
    php将IP地址转换为真实地址的方法
    PHP程序员要掌握哪些技术
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053326.html
Copyright © 2011-2022 走看看