hdu6154CaoHaha's staff(打表找规律)

来源:互联网 发布:pace.js 在线演示 编辑:程序博客网 时间:2024/06/05 22:48

题意:

给你n,让你在坐标系上画多边形,使得其面积大于等于n,输出最少的边数,边的长度可以为1或者根号2(对角)。

思路:

画前十几条边能凑的最大面积,然后找规律就好,比赛的时候只找出了偶数边的规律,奇数边没找到(只要那个7条边画出面积为5当时怎么也画不出来···,后来明白不能只能在一个方向上扩展边,要对称的扩展边,,=。=!)

代码:

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <vector>#include <map>#include <set>#include <cstdlib>#include <cmath>using namespace std;typedef long long ll;const ll INF = 0x3f3f3f3f;const ll INFF = 0x3f3f3f3f3f3f3f3f;const double inf = 1e18;const double eps = 1e-8;const ll mod = 1e9+7;double arr[1000005];int main(){    arr[4] = 2;    arr[5] = 2.5;    arr[6] = 4;    double tmp = 4;    int flag = 0;    int i = 6;    while(arr[i]<INF)    {        arr[i+2] = arr[i]+tmp;        if(flag==1)        {            tmp+=2;            flag = 0;        }        else            flag = 1;        i += 2;    }    tmp = 3;    i = 5;    while(arr[i]<INF)    {        arr[i+2] = arr[i]+tmp;        tmp++;        i += 2;    }    int t;    scanf("%d",&t);    while(t--)    {        int n;        scanf("%d",&n);        int ans = lower_bound(arr,arr+100005,n)-arr;        printf("%d\n",ans);    }    return 0;}

原创粉丝点击