1005 ——CaoHaha's staff


CaoHaha's staff              


    

官方题解:   


比赛的时候没有找出来,或者说是找错了,反正每次找规律都找不到,
菜啊啊啊啊啊啊啊
先讲一下自己的思路吧
先画一个八条边组成的面积为4 的正方形为基础,然后每次都扩展一个面积为2 的正方形。
然后错了,正确的思路是扩展一个    梯形    。
正确思路:



#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
//#include <bits/stdc++.h>
#define maxn 10010

using namespace std;


int a[10]={0,4,4,6,6,7,8,8,8};
int main()
{
    int T;
    int n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        if(n<=8)
        {
            printf("%d\n",a[n]);
            continue;
        }
        int x=floor(sqrt(n/2));
        int cnt=x*x*2;
        if(cnt==n)
            printf("%d\n",4*x);
        else if(cnt+x-0.5>=n)
            printf("%d\n",4*x+1);
        else if(cnt+x*2>=n)
            printf("%d\n",4*x+2);
        else if(cnt+3*x+0.5>=n)
            printf("%d\n",4*x+3);
        else
            printf("%d\n",4*x+4);
    }
    return 0;
}















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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值