博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 6154 CaoHaha's staff【找规律】【思维题】【好题】
阅读量:5967 次
发布时间:2019-06-19

本文共 2546 字,大约阅读时间需要 8 分钟。

CaoHaha's staff

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


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

题意:在一个二维坐标系中,想要得到一块为n的面积,问最少在坐标轴上面画多少笔画可以得到这样的面积,笔画可以是上、下、左、右、两种对角线共六种。

如果边为4k则面积为2*k*k,在加一条边,面积增加(k+k-1)/2,加两条则直接多一行,加三条面积增加(k+k+1)/2 【相当于在变最长的一条上往外延伸】,加4条又回到最初情况。

ps(注意输入可能为小数,还要注意计算面积的时候可能会爆int)

#include 
#define INF 0x3f3f3f3f#define ms(x,y) memset(x,y,sizeof(x))using namespace std;typedef long long ll;const double pi = acos(-1.0);const int mod = 1e9 + 7;const int maxn = 100000;double a[100000] = { 0 };void solve(){ for (ll i = 4; i <= maxn; i++) { if (i % 4 == 0) { a[i] = i*i / 8.0; } else { ll p = i % 4; ll q = i / 4; if (p == 1) { a[i] = q*q * 2.0 + (2.0 * q - 1.0) / 2.0; } else if (p == 2) { a[i] = q*(q + 1.0) * 2.0; } else if (p == 3) { a[i] = a[i-1] + (2.0 * q + 1.0) / 2.0; } } }}int main(){ //freopen("in.txt","r",stdin); //freopen("out1.txt","w",stdout); solve(); int t; scanf("%d", &t); while (t--) { double n; scanf("%lf", &n); int ans = lower_bound(a + 4, a + maxn, n) - a; printf("%d\n", ans); }}

转载于:https://www.cnblogs.com/Archger/p/8451570.html

你可能感兴趣的文章
跑带宽度多少合适_跑步机选购跑带要多宽,你的身体早就告诉你了
查看>>
深入理解Java的接口和抽象类
查看>>
Javascript异步数据的同步处理方法
查看>>
iis6 zencart1.39 伪静态规则
查看>>
SQL Server代理(3/12):代理警报和操作员
查看>>
Linux备份ifcfg-eth0文件导致的网络故障问题
查看>>
2018年尾总结——稳中成长
查看>>
度量时间差
查看>>
通过jsp请求Servlet来操作HBASE
查看>>
Shell编程基础
查看>>
Shell之Sed常用用法
查看>>
Centos下基于Hadoop安装Spark(分布式)
查看>>
3D地图的定时高亮和点击事件(基于echarts)
查看>>
mysql开启binlog
查看>>
设置Eclipse编码方式
查看>>
分布式系统唯一ID生成方案汇总【转】
查看>>
并查集hdu1232
查看>>
Mysql 监视工具
查看>>
Linux Namespace系列(09):利用Namespace创建一个简单可用的容器
查看>>
博客搬家了
查看>>