为了能到远方,脚下的每一步都不能少.|

园龄:粉丝:关注:

POI2012ROZ-Fibonacci Representation

POI #Year2012 #数学

贪心的每次选择最接近的两个数,x=min(xfibi1,fibix)

// Author: xiaruize
const int N = 2e5 + 10;
vector<int> vec;
int n;
void solve()
{
int res = 0;
cin >> n;
while (n)
{
auto it = upper_bound(ALL(vec), n);
n = min(n - (*prev(it)), (*it) - n);
res++;
}
cout << res << endl;
}
#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif
signed main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int testcase = 1;
vec.push_back(1);
vec.push_back(2);
while (vec[vec.size() - 1] + vec[vec.size() - 2] <= 1e18)
vec.push_back(vec[vec.size() - 1] + vec[vec.size() - 2]);
cin >> testcase;
while (testcase--)
solve();
#ifndef ONLINE_JUDGE
cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
return 0;
}

本文作者:xiaruize's Blog

本文链接:https://www.cnblogs.com/xiaruize/p/18156737

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   xiaruize  阅读(2)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起