zoukankan      html  css  js  c++  java
  • 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
    ", lower_bound(arr+4, arr+tot+1, s) - arr);
        }
    
        return 0;
    }
  • 相关阅读:
    web http协议
    swoole udp
    swoole线程和进程
    SVN中trunk,branches,tags用法详解
    mysql外键使用和事物使用
    xml
    dedecms开启报错
    Django CBV方法装饰器
    Django Cookie和Session
    ORM基础5
  • 原文地址:https://www.cnblogs.com/sbfhy/p/7413124.html
Copyright © 2011-2022 走看看