Hdu 6154 CaoHaha's staff【思维】

186 篇文章 0 订阅

CaoHaha's staff

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


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

题目大意:


在一个平面直角坐标系中,我们希望用最少的笔画去画出一个封闭图形,使得其包含的面积大于等于n.

我们每一笔可以画对角线或者沿着格子的边走。


思路:


我们不难发现,菱形的面积肯定是最大的,所以我们尽可能的去组成菱形,而我们通过贪心枚举不难发现,我们整个菱形的变化过程是:

1*1->1*2->2*2->2*3->3*3->3*4->4*4...........................


首先组成一个最小的菱形,然后我们拓展其当前菱形的最长边,多用一条边,就能够多获得最多的面积。

依次类推,我们模拟预处理一下就行。


Ac代码(略丑= =):

#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
int output[1500000];
int main()
{
    int pos;
    int x=2,y=2;
    int ans=8;
    int area=8;
    output[ans]=area;
    for(int i=0;;i++)
    {
        if(x>y)swap(x,y);
        ans++;
        area+=max(x,y)-1;
     //   printf("%d %d\n",ans,area);
        output[ans]=area;
        ans++;
        x++;
        area=x*y*2;
      //  printf("%d %d\n",ans,area);
        output[ans]=area;
        if(area>1000000000+1000000)
        {
            pos=ans;
            break;
        }
    }


    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        if(n<=2)
        {
            printf("4\n");
            continue;
        }
        if(n<=4)
        {
            printf("6\n");
            continue;
        }
        if(n==5)
        {
            printf("7\n");
            continue;
        }
        if(n==6)
        {
            printf("8\n");
            continue;
        }
        for(int i=1;i<pos;i++)
        {
            if(output[i]>=n)
            {
                printf("%d\n",i);
                break;
            }
        }

    }
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值