题目链接

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. 固态盘经常性蓝屏处理方法(WIN7/8)

    型号:intel 520S 大小;120G 我的是笔记本,这段时间辞职,有了时间折腾自己的电脑系统了,想装WIN8来着,PE下直接把固态盘的分区都干掉了,分了C,D(40G,剩下的空间),安装阶段完美 ...

  2. 【php】new static的用法

    在一个类中,常见的是new self()操作,代表返回自身类的实例. 当父类中存在方法,然后每个子类继承于父类,调用这个方法会返回自身的实例化对象, <?php class A { functi ...

  3. sublinme 快捷键格式

    {"keys": ["ctrl+shift+f"], "command": "reindent" , "arg ...

  4. Ubuntu终端命令--查看端口占用及关闭

    1.查看已连接的服务端口 (ESTABLISHED)     netstat-a 2.查看所有的服务端口(LISTEN,ESTABLISHED)     netstat-ap 3.查看指定端口,可以结 ...

  5. BZOJ3462 DZY Loves Math II(动态规划+组合数学)

    容易发现这是一个有各种玄妙性质的完全背包计数. 对于每个质数,将其选取个数写成ax+b的形式,其中x=S/pi,0<b<x.那么可以枚举b的部分提供了多少贡献,多重背包计算,a的部分直接组 ...

  6. Springboot返回html

    注:Springboot的版本2.1.3.RELEASE List-1 application.properties文件 server.port=8080 #url中,项目的前缀 server.ser ...

  7. C++模板编程中只特化模板类的一个成员函数

    模板编程中如果要特化或偏特化(局部特化)一个类模板,需要特化该类模板的所有成员函数.类模板中大多数成员函数的功能可能是一模一样的,特化时我们可能只需要重新实现1.2个成员函数即可.在这种情况下,如果全 ...

  8. BZOJ2159 Crash 的文明世界 【第二类斯特林数 + 树形dp】

    题目链接 BZOJ2159 题解 显然不能直接做点分之类的,观察式子中存在式子\(n^k\) 可以考虑到 \[n^k = \sum\limits_{i = 0} \begin{Bmatrix} k \ ...

  9. Java之File与递归

    File类的使用和递归思想 File类 概述 文件: 存储数据 文件夹: 管理文件与文件夹 构造方法 public File(String pathname) :通过将给定的路径名字符串转换为抽象路径 ...

  10. 利用poi来向execl中写入对象

    附上jar包下载链接: 附上百度网盘下载连接: 链接:https://pan.baidu.com/s/1t_jXUq3CuhZo9j_UI4URAQ 密码:r2qi package com.wz.po ...