CaoHaha's staff(hdoj6154)

CaoHaha’s staff

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

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

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

思路

看了好久才看懂题目
题意:你可以画单元格的边和对角线,至少画几笔才可以让面积大于等于k。

仔细分析后,a[i]是画了i笔后,得到的最大面积。
i从4开始 可以以一条对角线为边画个正方形,此时面积最大。
i+4 还是以两条对角线为边画正方型,此时面积最大。
i%4==2时 这时是在i-2的基础上的正方形,填两笔变为长方形。

也就是说如果i能被2整除是以对角线为边的矩形或者是正方形。
如果是奇数(i>5) 比如i为7 当i为6时,是一个1*2(以对角线为单位)的矩形,当为7时是以2为梯形的下底构成的一个新的图形。

#include<cstdio>
#include<math.h>
#include<iostream>
#include<string.h>
using namespace std;
#define MAXN 1000000001
long a[100001];

//long b[MAXN];
int flag = 0;
int main() {
    int T;
    scanf("%d", &T);
    memset(a, 0, sizeof(a));
    for (long long i = 4;; i++)
    {
        if (i==5)
        {
            continue;
        }
        if (i % 4 == 0) {
            a[i] = (i / 4)*(i / 4) * 2;
            //b[a[i]] = i;
        }
        else if (i % 2 == 0) {
            a[i] = (i / 4)*(i / 4 + 1) * 2;
            //b[a[i]] = i;
        }
        else
        {
            a[i] = a[i - 1] + (i - 2) / 4;
            //b[a[i]] = i;
        }
        if (a[i] > 1000000001) break;

    }
    while (T--)
    {
        long long n;
        scanf("%lld", &n);
            for (long long i = (long long )sqrt(8*n); ; i+=2)
            {
                if (a[i]>=n)
                {
                    if(a[i-1]>=n)
                        printf("%ld\n", i-1);
                    else
                    {
                        printf("%ld\n", i);
                    }
                    break;
                }
            }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值