hdu6154 找规律

hdu6154   CaoHaha's staff

题意:问在方格上最少用多少笔可以画出面积不小于S的图,笔画只能横竖斜。

tags:笔画肯定尽量斜的最优。规律是:如果当前画出了一个矩形,那接下来的两笔肯定是在较长边上加。所以打出表即可。

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a; i<=b; ++i)
#define per(i,b,a) for (int i=b; i>=a; --i)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int s, arr[N], tot;
void Init()
{
    int a = 2, b = 1;
    arr[4]=2, arr[5]=2, arr[6]=4;
    rep(i,7,N-1)
    {
        if(i&1) arr[i] = arr[i-1]+a-1;
        else {
            arr[i] = arr[i-2]+a*2;
            b += 1;
            if(a<b) swap(a, b);
        }
        if(arr[i]>1e9) { tot=i;  break; }
    }
}
int main()
{
    Init();
    int T;  scanf("%d", &T);
    while(T--)
    {
        scanf("%d", &s);
        printf("%d\n", lower_bound(arr+4, arr+tot+1, s) - arr);
    }

    return 0;
}

转载于:https://www.cnblogs.com/sbfhy/p/7413124.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值