题目代号:HDU 6154

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154

CaoHaha's staff

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


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

[2017中国大学生程序设计竞赛 - 网络选拔赛]( http://acm.hdu.edu.cn/search.php?field=problem&key=2017%D6%D0%B9%FA%B4%F3%D1%A7%C9%FA%B3%CC%D0%F2%C9%E8%BC%C6%BE%BA%C8%FC+-+%CD%F8%C2%E7%D1%A1%B0%CE%C8%FC&source=1&searchmode=source)

题目大意:有一个巫师可以在一个带有xOy坐标系的魔术场地上画传送阵,他画的传送阵面积要大于或等于需要传送物品的面积,他每分钟只能画一条边,这条边能是每个单位方块的边或者对角线(即每次能画单位长度为1的边或者\(\sqrt2\)的对角线)现在他希望用最小的时间画出满足需要的面积的传送阵,他需要你的帮助。

解题思路:使面积最大化,即尽量使用对角线进行绘制传送阵。

现在需要讨论的是对于面积的特殊情况,现在根据下图来看一看:



很显然,在原来的基础上只增加了一条边,但是面积却增加了1.5,也就是说当面积为9的时候,只需要在8条边的基础上增加一条边即可使覆盖面积达到10.5,那么同理,当某条边的长度很长的时候那么在原先的基础上只需要增加一条边,面积却扩大了很多,并且这是最优的画法(只需增加一笔即可扩展出一个梯形)

并且当有两个连续边各增加一个梯形后,可以将两条小边扩展成直角如下图所示,



同理,当一个正方形每条边增加一笔即可将整个正方形的边长增加\(\sqrt2\)这是显然的,再看看下图



这样是最优的画法,相同的边时使面积最大化。

下面放上AC代码:

# include <bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(false);
typedef unsigned long long ULL;
typedef long long LL;
///coding................................... int main()
{
IOS
#ifdef FLAG
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif /// FLAG
LL n,t,a[10]={0,4,4,6,6,7,8,8,8};
cin>>t;
while(t--) {
cin>>n;
if(n<=8)cout<<a[n]<<endl;
else {
LL l=0;
while(2*l*l<=n)++l;--l;
if(n==2*l*l)cout<<4*l<<endl;
else if(n<=2*l*l+l-0.5)cout<<4*l+1<<endl;
else if(n<=2*l*l+2*(l-0.5)+1)cout<<4*l+2<<endl;
else if(n<=2*l*l+3*(l-0.5)+2)cout<<4*l+3<<endl;
else cout<<4*l+4<<endl;
} }
return 0;
}

HDU 6154 CaoHaha's staff(2017中国大学生程序设计竞赛 - 网络选拔赛)的更多相关文章

  1. HDU 6154 - CaoHaha's staff | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    /* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的 ...

  2. HDU 6150 - Vertex Cover | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组 ...

  3. HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...

  4. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)

    Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in ...

  5. 2017中国大学生程序设计竞赛 - 网络选拔赛 1005 HDU 6154 CaoHaha's staff (找规律)

    题目链接 Problem Description "You shall not pass!" After shouted out that,the Force Staff appe ...

  6. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff 思维

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角 ...

  7. CaoHaha's staff (HDU 6154)(2017中国大学生程序设计竞赛 - 网络选拔赛)

    Problem Description "You shall not pass!" After shouted out that,the Force Staff appered i ...

  8. 【2017中国大学生程序设计竞赛 - 网络选拔赛 && hdu 6154】CaoHaha's staff

    [链接]点击打开链接 [题意] 给你一个面积,让你求围成这个面积最少需要几条边,其中边的连线只能是在坐标轴上边长为1的的线或者是两个边长为1 的线的对角线. [题解] 找规律题 考虑s[i]表示i条边 ...

  9. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...

随机推荐

  1. JavaScript设计模式(发布订阅模式)

    发布—订阅模式又叫观察者模式,它定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都将得到通知.在JavaScript开发中,我们一般用事件模型来替代传统的发布—订阅模式 ...

  2. 【ES6 】var/let/const的区别

    var 声明变量 没有区级作用域 可以预解析 可以重复定义 声明的全局变量属于顶层对象(window)的属性 let 声明变量 有块级作用域 没有预解析 不可以重复定义 声明的全局变量不属于顶层对象( ...

  3. Tika提取文件元数据

    Tika可以从文件中提取元数据. 什么是元数据: 元数据是文件所提供的的附件信息即文件的属性. word文档的元数据: Tika提取元数据: 我们可以使用文件parse()方法提取元数据,传递一个空的 ...

  4. 使用JavaFX开发桌面程序(一)

    使用JavaFX开发桌面程序 注:我也是JAVA FX的初学者之一,自己在学习的时候踩了许多的坑,中文英文的资料查了不少,但是觉得FX技术和其他热门技术相比,教程还是太少了.这里就尽量做一点微小的贡献 ...

  5. pthread 笔记

    1.创建线程 res = pthread_create(&a_thread, NULL, thread_function1, NULL); if (res != 0) { perror(&qu ...

  6. springBoot2.x 支持跨域请求配置

    提供三种配置方式: 1.配置过滤器,实现 WebMvcConfigurer接口(springboot2.x的方式) @Configuration public class GlobalCorsConf ...

  7. API工具下载地址记录一下

    java 1.6 帮助文档中文链接:http://download.csdn.net/detail/qw599186875/9608735 中文 – 谷歌版在线版: https://blog.fond ...

  8. 第十五章、Python多线程之信号量和GIL

    目录 第十五章.Python多线程之信号量和GIL 1. 信号量(Semaphore) 2. GIL 说明: 第十五章.Python多线程之信号量和GIL 1. 信号量(Semaphore) 信号量用 ...

  9. Delphi MSComm控件事件的介绍

  10. QQ空间添加背景音乐

    QQ空间背景音乐方式 1.QQ音乐添加背景音乐一种是开通绿砖[有矿的忽略此条]2.QQ空间添加网络音乐的方法步骤:1.首先,需要先下载好想要音乐作为QQ空间背景音乐的歌曲文件(建议为MP3格式)[我这 ...