hdu6154CaoHaha's staff (2017 online competition rules)

CaoHaha's staff

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


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
 

Source

Calculate the minimum number of line segments required to draw a graph with an area of ​​n. The line can only be drawn diagonally and in the coordinate direction. It can be imagined that there are many small squares in the square, and each small square has an area of ​​1, so that When you draw 4 line segments for the first time, you can use four diagonal lines to draw the largest area √2* √2=2. When you draw 5 lines, it is equivalent to a pentagon, with a small triangle line and an area of ​​2 +0.5=2.5,
When there are six lines, a quadrilateral is added to the original quadrilateral, and the area of ​​2+2=4 is maximized. When there are seven sides, when a hexagon is formed, two sides are removed, and a trapezoid is formed on the rectangle, and the area is maximized. , the area is 4+3=7. When there are eight lines, the largest area is the large square formed by two hexagons, and the area is 8. From this, the rule is drawn:
/**
   by z_guibin
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
#define N 100005
double dp[N];
void solve()
{
    double x=0.5,y=2;
    dp[4]=2;


    for(int i=5; i<=N; i++)
    {
        if(i%4==1)
            dp[i]=dp[i-1]+x,x+=1.0;
        else if(i%4==2)
            dp[i]=dp[i-2]+y,y+=2.0;
        else if(i%4==3)
            dp[i]=dp[i-1]+x;
        else if(i%4==0)
            dp[i]=dp[i-2]+y;
    }
}
intmain()
{
    double n;
    solve();
    int t;
    scanf("%d",&t);
    while(t--)
    {
        cin>>n;




        for(int i=4; i<=N; i++)
        {
            if(dp[i]>=n)
            {
                cout<<i<<endl;
                break;
            }
        }


    }
    return 0;
}
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518053&siteId=291194637