题目链接

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×1的小正方形来说,它的四条边和两条对角线可以看作任意的一条边,现在给定一个面积,求围成如此大的面积最少需要多少条边。

分析:

本来打算画个图的,这样看起来比较直观一点,但是这图实在太难画了,就直说一下把。

我们首先根据边数来确定它能围成的最大面积,然后根据面积找到第一个大于等于它的边数。

如果是4条边的话,肯定是由四条对角线构成,面积为2

如果是5条边的话,是在由四条对角线构成的图形的基础上,将其中的一条边展开,换成两条边,面积加上0.5,总面积为2.5

6条边的话,是在由四条对角线构成的图形的基础上,将其中的一条边往上移动一个,加在上另外两条边,面积加上2,总面积为4

7条边的话,将6条边的图像的长边展开,分别由对角线移动到边线上,增加一天对角线封顶,比原来的图像面积加上1.5,总面积为5.5

8条边的话,就是原来6条边的图形,长边向外移动一格,面积增加4,总面积为8

9条边的话,将8变形一条边向外扩,如同4变形变为5变形,面积增加1.5,变为9.5

10条边的话,如同4边形变为6边形,面积增加4,总面积为12

11条边的话,就是将10边形的长边展开,如同6边形变为7边形,面积增加2.5,变为14.5

····

从这里我们就可以发现,它们i安华的规律是四个一个周期,在一个周期里,奇数边满足(首相为1.5,公差为1的等差数列),偶数边满足(首相为4,公差为2的等差数列),(因为我们首先要找到前几项作为基础,所以从边数为8的开始)

代码:

#include <bits/stdc++.h>
using namespace std;
const int MAX=90000;
double area[MAX],f=1.5,p=4;
int cnt;
void makeTable()
{
area[3]=0.5;
area[4]=2;
area[5]=2.5;
area[6]=4;
for(int i=7; i<=MAX; i++)
{
int y=i%4;
if(y==1)
{
area[i]=area[i-1]+f;
f+=1.0;
}
if(y==2)
{
area[i]=area[i-2]+p;
p+=2.0;
}
if(y==3)
{
area[i]=area[i-1]+f;
}
if(y==0)
{
area[i]=area[i-2]+p;
}
}
}
int main()
{
makeTable();
int T;
scanf("%d",&T);
while(T--)
{
double n;
scanf("%lf",&n);
for(int i=3; i<=MAX; i++)
{
if(area[i]>=n)
{
printf("%d\n",i);
break;
}
}
}
return 0;
}

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

  1. 2017中国大学生程序设计竞赛 - 网络选拔赛 1004 HDU 6153 A Secret (字符串处理 KMP)

    题目链接 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a presen ...

  2. 2017中国大学生程序设计竞赛 - 网络选拔赛 1003 HDU 6152 Friend-Graph (模拟)

    题目链接 Problem Description It is well known that small groups are not conducive of the development of ...

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

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

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

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

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

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

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

    题目代号:HDU 6154 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 CaoHaha's staff Time Limit: 2000/1 ...

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

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

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

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

  9. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph(暴力搜索)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6152 Problem Description It is well known that small ...

随机推荐

  1. [学习]Windows server 使用控制台时容易卡死的解决方法

    公司使用Windows server 下面的 cmd 命令行 控制台打开某一个 bat 文件的方式 进行后台使用.. 但是经常发现在winserver 2016 时 遇到卡死的情况, 今天中午我再进行 ...

  2. 手机H5显示一像素的细线

    手机屏幕分辨率的问题,导致h5的1像素看起来比较粗,网上找了一个办法,记下来 主要就是通过scale来缩小宽度 .line1px{     border: none;     border-botto ...

  3. 【BZOJ4999】This Problem Is Too Simple!(线段树)

    [BZOJ4999]This Problem Is Too Simple!(线段树) 题面 BZOJ 题解 对于每个值,维护一棵线段树就好啦 动态开点,否则空间开不下 剩下的就是很简单的问题啦 当然了 ...

  4. jumpserver 堡垒机搭建

    1.摘要 Jumpserver 是一款由python编写开源的跳板机(堡垒机)系统,实现了跳板机应有的功能.基于ssh协议来管理,客户端无需安装agent. 特点: 完全开源,GPL授权 Python ...

  5. 单点登录(十二)-----遇到问题-----cas启用mongodb验证方式登录后没反应-pac4j-mongo包中的MongoAuthenticatInvocationTargetException

    cas启用mongodb验证方式登录后没反应 控制台输出 2017-02-09 20:27:15,766 INFO [org.jasig.cas.authentication.MongoAuthent ...

  6. fzyzojP3412 -- [校内训练20171212]奇数

    套路地, 考虑dfs树上搞事情 容易发现,对于(x,y)如果dfs树上距离为奇数,或者dfs树上路径中有一条边在某个简单奇环上,那么可以经过奇数条边到达 判断边在某个奇环上: 点双,点双中黑白染色,如 ...

  7. [CQOI2016] 手机号码 (数位dp)

    link $solution:$ $10^{10} \leq L \leq R < 10^{11}$这个数据范围很容易想到数位$dp$. 依照题意模拟即可. #include<iostre ...

  8. php 性能优化

    php 性能测试工具 ab(Apache Benchmark) ab 是由 Apache 提供的压力测试软件.安装 apache 服务器时会自带该压测软件. 如何使用: ab -n1000 -c100 ...

  9. bzoj 2055 80人环游世界

    有源汇上下界最小费用可行流. 将每个国家拆点. 源点向一个新建节点连一条上界为总人数下界为0费用为0的边. 新建节点向每个国家的入点连一条上界为正无穷下界为0费用为0的边. 每个国家的入点向出点连一条 ...

  10. UVALive 7505 Hungry Game of Ants (2015Ecfinal)

    题意: 长度是n的线段上点的编号从1~n,每个点有一只蚂蚁蚂蚁的体重等于该点的编号,最初每只蚂蚁可以选择向右走或者向左走两只蚂蚁相遇时体重大的吃掉体重小的并且体重增加为两只的体重和,走到边界时掉头,问 ...