HDU 6154 CaoHaha's staff

来源:互联网 发布:qq管家软件管理 编辑:程序博客网 时间:2024/06/05 10:17

CaoHaha's staff

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


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
512345
 

Sample Output
44667
 

Source
2017中国大学生程序设计竞赛 - 网络选拔赛
 

Recommend
liuyiding

题意:一个每个格子都是面积为1 的 网格中, 围出面积 n需要多少条线。

分析:
画图可以找到规律。

AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;double ans[100000];int main(){    ans[4]=2.0,ans[5]=2.5,ans[6]=4.0;    long long f1=1,f2=1,cnt=0;    double p1=1.5,p2=2.5;    for(int i=7;ans[i-1]<=1e9;i++)    {ans[i]=ans[i-1];if(i%2){    ans[i]+=p1;    f1++;    if(f1%2)    p1++;}else{    ans[i]+=p2;    f2++;    if(f2%2)p2++;}cnt++;    }    int T;    scanf("%d",&T);    while(T--)    {double n;scanf("%lf",&n);int p=lower_bound(ans+4,ans+4+cnt,n)-ans;printf("%d\n",p);    }}


 
原创粉丝点击