2017中国大学生程序设计竞赛 - 网络选拔赛 1005 HDU 6154 CaoHaha's staff (找规律)
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 (找规律)的更多相关文章
- 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 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 1003 HDU 6152 Friend-Graph (模拟)
题目链接 Problem Description It is well known that small groups are not conducive of the development of ...
- HDU 6154 - CaoHaha's staff | 2017 中国大学生程序设计竞赛 - 网络选拔赛
/* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的 ...
- HDU 6150 - Vertex Cover | 2017 中国大学生程序设计竞赛 - 网络选拔赛
思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组 ...
- HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛
普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...
- HDU 6154 CaoHaha's staff(2017中国大学生程序设计竞赛 - 网络选拔赛)
题目代号:HDU 6154 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 CaoHaha's staff Time Limit: 2000/1 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)
Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph(暴力搜索)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6152 Problem Description It is well known that small ...
随机推荐
- 视频剪辑软件-PR (Adobe Premiere)
1.PR 是什么? Adobe Premiere 是一款常用的视频编辑软件,由Adobe公司推出.PR是一款编辑画面质量较好的软件,有较好的兼容性,且可以与Adobe公司推出的其他软件相互协作.目前这 ...
- [转帖] CentOS7 与 CentOS6的对比
来源网站: http://blog.51cto.com/fengery/1901349 centos6.x_centos7.x差异改进明细 感谢原作者 centos官方帮助文档:https://wik ...
- Oracle 11G RAC For Windows 2008 R2部署手册(亲测,成功实施多次)
总体规划 服务器规划 1.建议使用两台硬件配置一模一样的服务器来作为 RAC 环境的两个物理节点 2.服务器至少需要配置两块物理网卡 3.服务器规划表: 节点 主机名 本地磁盘大小 操作系统 内存大小 ...
- Word中怎样删除分节符而不影响前节页面设置
在Word中,通过常规方法删除一个不需要的分节符时,会默认将分节符后面的页面设置带入前一节.比如,第一节是纵向排版,第二节是横向排版,当删除第二节的全部内容,包括二者之间的分节符之后,就会使得第一节的 ...
- 是否升级IOS11?IOS11不支持32位程序 查看手机哪些APP不支持
查看苹果32位APP具体步骤:设置-通用-关于本机-应用程序.如果手机中下载了32位应用的话,苹果会给出应用兼容性提醒:如果手机里没有安装32位应用,右侧没有小三角,点击“应用程序”也会没有反应. I ...
- BZOJ 2143 飞飞侠(分层最短路)
飞飞国是一个N×M的矩形方阵,每个格子代表一个街区.然而飞飞国是没有交通工具的.飞飞侠完全靠地面的弹射装置来移动.每个街区都装有弹射装置.使用弹射装置是需要支付一定费用的.而且每个弹射装置都有自己的弹 ...
- Python 变量 (上)
Python通过变量引用内存中的值,变量的值占用多少空间是由变量的类型决定的.声明变量不需要指定变量的类型,解释器会自动根据值来判断.变量名称必须符合标识符的定义 标识符 标识符是由字母,数字和下划线 ...
- 概率主题模型简介 Introduction to Probabilistic Topic Models
此文为David M. Blei所写的<Introduction to Probabilistic Topic Models>的译文,供大家参考. 摘要:概率主题模型是一系列旨在发现隐藏在 ...
- module.exports 、 exports 和 export 、 export default 、 import
1:commonjs规范 module.exports={a:10,b:20} var test=require('lib/test') console.log(test.a);console.log ...
- Android Studio 导入系统 jar包
1.当前需要导入系统jar包的module所对应build.gradle中添加如下依赖: provided files('libs/classes-full-debug.jar') 也可以图形化设置: ...