题目链接

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. Apache+Nginx+php共存(一)

    在实际开发中个人的电脑中经常需要安装 WNMRP.WAMRP.LNMRP.LAMRP等各种开发环境来应对不同的开发需求. 此篇主要是对WINDOWS系统下 Apache+Nginx + PHP +My ...

  2. [微软官方]FSUTIL

    Applies To: Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7, Windows Server 2003 ...

  3. PHP开发网站,你是如何提高其网站的安全性的?

    一.网站程序问题 很多网站的安全问题大多是由于网站程序存在漏洞,所以想要提高网站安全性,必须要选择安全的后台cms系统,若有能力可以自己去开发网站后台,这样安全性能得到极大的提高,若是从网上选择一些免 ...

  4. 重温SQL——行转列,列转行

    行转列,列转行是我们在开发过程中经常碰到的问题.行转列一般通过CASE WHEN 语句来实现,也可以通过 SQL SERVER 2005 新增的运算符PIVOT来实现.用传统的方法,比较好理解.层次清 ...

  5. 【Python】python 2 map() reduce()

    利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字.输入:['adam', 'LISA', 'barT'],输出:['Adam', 'Lisa', 'Bart']. ...

  6. 【BZOJ1034】泡泡堂(贪心)

    [BZOJ1034]泡泡堂(贪心) 题面 BZOJ 洛谷 题解 很基础的贪心,然而我竟然没写对...身败名裂. 大概就是类似田忌赛马. 先拿看当前最大值是否能否解决对面最大值,否则检查能否用最小值来兑 ...

  7. linux内核分析 第八周 理解进程调度时机跟踪分析进程调度与进程切换的过程

    笔记: 实验:使用gdb跟踪分析一个schedule()函数

  8. mybatis.5.动态SQL

    1.动态SQL,解决关联sql字符串的问题,mybatis的动态sql基于OGNL表达式 if语句,在DeptMapper.xml增加如下语句; <select id="selectB ...

  9. Android ListView 几个重要属性

    Android ListView 几个重要属性http://blog.csdn.net/avenleft/article/details/7334060 android:transcriptMode= ...

  10. Eureka的原理

    http://blog.csdn.net/awschina/article/details/17639191 关于AWS的区域和可用区概念解释: Eureka的原理:Region与Zone. 因为在编 ...