HDU 6154 CaoHaha's staff

来源:互联网 发布:魔戒巫师知乎 编辑:程序博客网 时间:2024/06/05 00:38

CaoHaha's staff

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


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
512345
 

Sample Output
44667


题意:在方格中画线,可以沿方格边或者对角线画,给出要求圈出的面积,求最少需要多少根线

找到规律打一个表,多少根线最多可以围出的面积,然后二分去找下标。

这题还有点不懂,比如7根线可以围出5.5但怎么围出5?


#include <cstdio>#include <cstring>#include <algorithm>#define M 90000using namespace std;__int64 n;double a[M];void init(){    int i,I;    for (i=4 ; i<M; i++)    {        I=i/4;        if (i % 4 == 0)            a[i] = I*I*2;        else if ((i-1) % 4 == 0)            a[i] = a[i-1]+I-0.5;        else            a[i] = a[i-1]+I+0.5;    }}int main(){    init();    int T,i,j,f,r;    scanf("%d", &T);    while (T--)    {        scanf("%I64d", &n);        printf("%d\n",lower_bound(a+4, a+M-1, n)-a);    }    return 0;}