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 are a staff with infinity power. If You can use it skillful,it could help you to do whatever you want.
But Now,his new Owner,caohaha,is a sorcerers apprentice. He can only use this staff to send things
Today,dreamwyy come to caohaha.requesting him send a toy to his new girl friend. It is so far this dreamwyy can only resort to Caohaha.
The first step to send something are 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 Diago Nals. In additional,you need 1 minutes to draw a segments.
If you want to send something, you need to draw a Magic array which are not smaller than the. You can make it any deformation,so what really matters is the size of the object.
Caohaha want to help Dreamwyy but the his time is valuable (to learn to being just like you), so he want to draw least segments. However,because's 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
The least time Caohaha can send the toy.
Sample Input
5
1
2
3
4
5
Sample Output
4
4
6
6
7
Ideas:
As shown in the following illustration, first of all we should prefer the diamond expansion, first on its side can be added by adding an edge, so that it can be added on this side of the area such as the shadow of a diagonal line is shown. When we expand the number of sides greater than or equal to two, it will appear in the top of the graph is marked with a small spiral triangle, so that the next side of the two edge pull over the area can be increased by 1, so that the maximum expansion of four times to find the solution. A small number of sides requires a special sentence.
#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; }