hdu-6156 CaoHaha's staff

题意:给一个数n,我们可以沿着横线和对角线上化一条线,求:画出来的面积大于等于N的最小笔画是多少。

思路:贪心的选择斜线画法,然后我们可以知道当前最大能构成的矩形的长和宽,假设我们可以再加大,自然是高加1,那么面积就会扩大 (长 * 1),然后再,考虑5出现6次的原因,是在长的那边在4的画法的情况下只需增加一个笔画,而面积可以增加很多,所以,求出这个面积再特判,贪心加斜线,然后再考虑加1的情况。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#define LL long long
#define siz 1000005

using namespace std;
const int mod = 1e9+7;
int n;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        if(n==1||n==2){
            puts("4");continue;
        }
        if(n==3){
            puts("6");continue;
        }
        int L,wide;
        L = 2,wide = 1;
        while(L*wide*2<=n){
            if(L*(wide+1)*2>n) break;
            wide = wide + 1;
            if(wide>L) swap(L,wide);
        }
        int ans;
  //      cout<<L<<" "<<wide<<endl;
        if(L*wide*2 == n){
            ans = (L + wide)*2;
        }
        else{
            int m = n - L * wide *2;
            //cout<<2*l
            int zx = ((L * 2) - 1) / 2;
            //if(L%2==0) --zx;
            if(zx >= m){
                ans = 2*(L + wide) +1;
            }
            else{
                ans = (L + wide)*2 + 2;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值