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,对角线的长度是2^(1/2)(根号2),让用最少的线段来画出可以满足的面积。因为2^(1/2)要长,所以可以多画对角线,少画边,那么画出图形在面积小于8的时候是特殊情况,如果大于8,才会出现规律,按照画菱形的方法(以一开始是2条对角线构成的菱形为例),每次加一条线,可以增加面积1.5,增加两条线,这两条线又可以合并,面积增加2.5,增加三条线,面积增加2.5,增加4条线,也就又构成了一个新的正方形,面积在三条线的基础上又增加了3.5。所以只要找到能够符合面积的范围,在这个基础上选择增加的线即可。

    

(图片截自http://www.cnblogs.com/teble/p/7425292.html,如有侵权,立即删除)。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll t, n;
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
if(n==1||n==2)printf("4\n");
else if(n==3||n==4) printf("6\n");
else if(n==5) printf("7\n");
else if(n>=6&&n<=8) printf("8\n");
else
{
long long m = floor(sqrt(n/2));
long long ans = m*4;
long long x=m*m*2;
if(n==x)printf("%lld\n", ans);
else if(n<=x+m-0.5)printf("%lld\n", ans + 1);
else if(n<=x+2*m)printf("%lld\n", ans + 2);
else if(n<=3*m+0.5+x)printf("%lld\n", ans + 3);
else printf("%lld\n", ans + 4);
}
}
return 0;
}

最新文章

  1. 浅谈为之奋斗过的Set接口
  2. [题解]洛谷月赛 Hello World(升级版)
  3. atitit.提升2--3倍开发效率--cbb体系的建设..
  4. UVa 1339 Ancient Cipher --- 水题
  5. MySQL root密码重置 报错:mysqladmin: connect to server at &#39;localhost&#39; failed的解决方案
  6. ASP.NET知识集
  7. Linux进程管理之task_struct结构
  8. centos下redis和nginx软件的安装
  9. autoscan; aclocal; autoconf; automake --add-missing; ./configure; make
  10. 李洪强漫谈iOS开发[C语言-025]-赋值运算符案例
  11. WebWorker SharedWorker ServiceWorker
  12. [LeetCode129]Sum Root to Leaf Numbers
  13. Android自己定义组件系列【8】——面膜文字动画
  14. linux 内核的futex
  15. 并行cmd
  16. js压缩上传图片
  17. 如何将VMware虚拟机迁移到AWS
  18. redis集群配置与管理
  19. 【Machine Translation】CMU的NMT教程论文:最全面的神经机器翻译学习教程
  20. 搜索核心原理之网页和查询的相关性——TF-IDF

热门文章

  1. linux下mysql部署
  2. varnishlog、Varnishstat详解
  3. Python占位符使用总结
  4. iPhone开发视频教程 Objective-C部分
  5. 基于【 springBoot +springCloud+vue 项目】三 || 项目部署
  6. SparkSQL读取HBase数据
  7. 解决npm ERR!Unexpected end of JSON input while paring near (解析附近时JSON输入意外结束)&#39;....&quot;^2.0.0-rc.0&quot;,&quot;glob&quot;&#39;等npm install错误
  8. Oracle数据库(实例)删除用户和表空间
  9. linux下Django Nginx+uwsgi 安装配置
  10. C语言memset函数详解