hdu6154-CaoHaha's staff(找规律)

本文介绍了一道程序设计竞赛题目,目标是最少时间内绘制出足够大的魔阵以传送特定大小的玩具。通过规律发现,文章提供了一种有效算法来解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

CaoHaha's staff

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


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分钟画一段。求所需的最短时间 。
解析:这是个找规律的题,每增加4条线,所围成的魔法阵扩大一圈,思考下为什么s等于5的时候答案是7,具体看图吧d(´ω`*)
不用double也能过,注意向下取整就行了

 
#include <iostream>
#include <string>
using namespace std;
typedef long long LL;
double maxx[500000];
int main()
{
    LL t,n;
    for(LL i=1;i<=500000;i++)
    {
        if(i%4==0) maxx[i]=(i/4)*(i/4)*2;
        if(i%4==1) maxx[i]=maxx[i-1]+i/4-0.5;
        if(i%4==2) maxx[i]=maxx[i-2]+2*(i/4);
        if(i%4==3) maxx[i]=maxx[i-1]+i/4+0.5;

    }
    ///for(int i=5;i<=500;i++)
    /// cout<<maxx[i]<<endl;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(LL i=4;i<500000;i++)
        {
            if(maxx[i]>=n)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值