2017 ccpc网络预选赛 CaoHaha's staff

CaoHaha’s staff

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0

Problem Description
“You shall not pass!”
After shouted out that,the Force Staff appered in CaoHaha’s hand.
As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.
But now,his new owner,CaoHaha,is a sorcerers apprentice.He can only use that staff to send things to other place.
Today,Dreamwyy come to CaoHaha.Requesting him send a toy to his new girl friend.It was so far that Dreamwyy can only resort to CaoHaha.
The first step to send something is draw a Magic array on a Magic place.The magic place looks like a coordinate system,and each time you can draw a segments either on cell sides or on cell diagonals.In additional,you need 1 minutes to draw a segments.
If you want to send something ,you need to draw a Magic array which is not smaller than the that.You can make it any deformation,so what really matters is the size of the object.
CaoHaha want to help dreamwyy but his time is valuable(to learn to be just like you),so he want to draw least segments.However,because of his bad math,he needs your help.

Input
The first line contains one integer T(T<=300).The number of toys.
Then T lines each contains one intetger S.The size of the toy(N<=1e9).

Output
Out put T integer in each line ,the least time CaoHaha can send the toy.

Sample Input
5
1
2
3
4
5

Sample Output
4
4
6
6
7

就是让你在一个坐标里面画线每次只能画一条边或者对角线,让他们包围的面积大于等于你输入的size

下面是图形面积变化的示意图,注意要尽可能的选择对角线当边

这里写图片描述


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <map>
#define PI acos(-1.0)
#define mod 1e9+7
#define inf 0x3f3f3f3f
using namespace std;


int main()
{

    int t,n,m;
    scanf("%d",&t);
    while(t--)
    {

        scanf("%d",&n);
        if(n==0)printf("0\n");
        else if(n==1)printf("4\n");
        else if(n==2)printf("4\n");
        else
        {
            m=sqrt(n/2);
            //当正好是正方形的时候
            if(m*m*2==n)printf("%d\n",m*4);
            else if(m*(m+1)*2==n)printf("%d\n",m*4+2);
            else if(n>m*m*2&&n<(m+1)*m*2)
            {
                if(n<=m*m*2+m-1)printf("%d\n",m*4+1);
                else printf("%d\n",m*4+2);
            }
            else if(n>m*(m+1)*2)
            {
                if(n<=m*(m+1)*2+m)printf("%d\n",m*4+3);
                else printf("%d\n",m*4+4);
            }
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值