1005 ——CaoHaha's staff

来源:互联网 发布:淘宝店铺网名昵称大全 编辑:程序博客网 时间:2024/05/29 18:25


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 10010using 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;}















原创粉丝点击