hdu6154CaoHaha's staff

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

思路:
如下图所示,首先我们应该优先选择菱形扩展,先在其一侧可以通过添加一条边,这样就可以在其这一侧增加的面积如斜线的阴影所示。当我们扩展的边数大于等于二的时候,就会出现图中最上方标有螺旋状的小三角形,这样将旁边的两条边拉过来就可以将面积再增加1;这样最多扩展四次就可以找到解。边数较小的情况需要特判。
扩展图解

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long n;
        cin>>n;
        if(n==1||n==2)
            puts("4");
        else if(n==3||n==4)
            puts("6");
        else if(n==5)
            puts("7");
        else if(n>=6&&n<=8)
            puts("8");
        else
        {
            long long m=floor(sqrt(n/2));
            // printf("%d\n",m);
            long long tmp=m*4;
            long long x=m*m*2;
            if(n==x)
                cout<< tmp<<endl;
            else if(n<=x+m-0.5)
                cout<< tmp+1<<endl;
            else if(n<=x+2*m)
                cout<< tmp+2<<endl;
            else if(n<=3*m+0.5+x)
                cout<< tmp+3<<endl;
            else
                cout<< tmp+4<<endl;
        }
    }
    return 0;
}
  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值