zoukankan      html  css  js  c++  java
  • [BZOJ2796][Poi2012]Fibonacci Representation

    由于是斐波那契数列,所以$x_i+x_j<=x_k,i<j<k$

    所以猜测可以贪心选择两边近的数处理。

     1 #include<cstdio>
     2 #include<algorithm>
     3 #define ll long long
     4 #define mid (l+r>>1)
     5 using namespace std;
     6 ll f[505],tot=1;
     7 inline ll findl(ll x)
     8 {
     9     int l=1,r=tot,ans=1;
    10     while(l<=r)
    11     {
    12         if(f[mid]<=x)ans=mid,l=mid+1;
    13         else r=mid-1;
    14     }
    15     return f[ans];
    16 }
    17 inline ll findr(ll x)
    18 {
    19     int l=1,r=tot,ans=1;
    20     while(l<=r)
    21     {
    22         if(f[mid]>=x)ans=mid,r=mid-1;
    23         else l=mid+1;
    24     }
    25     return f[ans];
    26 }
    27 int solve(ll x)
    28 {
    29     ll l=findl(x),r=findr(x);
    30     if(l==r)return 1;
    31     if(x-l<=r-x)return solve(x-l)+1;
    32     return solve(r-x)+1;
    33 }
    34 int main()
    35 {
    36     f[0]=f[1]=1;
    37     while(f[tot-1]<=4e17)
    38     f[++tot]=f[tot-1]+f[tot-2];
    39     int t;scanf("%d",&t);
    40     ll x;
    41     while(t--)scanf("%lld",&x),
    42     printf("%d
    ",solve(x));
    43 }
    View Code
  • 相关阅读:
    Java基本数据类型的包装类
    Java数据类型基础
    Xscan安装
    Notepad++配置HexEditor插件
    [WP]XCTF-re2-cpp-is-awesome
    [WP]XCTF-tt3441810
    [WP]XCTF-re1-100
    [WP]XCTF-Mysterious
    [WP]xctf-parallel-comparator-200
    [WP]XCTF-elrond32
  • 原文地址:https://www.cnblogs.com/xuruifan/p/5191205.html
Copyright © 2011-2022 走看看