bzoj 2796: [Poi2012]Fibonacci Representation
结论貌似是,,,肯定只有没有重复的数字。http://hzwer.com/6426.html
一开始猜的是贪心,感觉也是可以的啊。。。(想想都有道理,然而看到是神奇的(dp类)记忆化搜索,直接虚的不敢写。。)
#include <bits/stdc++.h>
#define LL long long
#define lowbit(x) x&(-x)
#define inf 2e18
using namespace std;
inline LL ra()
{
LL x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
LL f[],n;
int top,P;
map<LL, int > F;
int solve(LL x)
{
if (F[x]) return F[x];
int t=lower_bound(f,f+top,x)-f;
if (f[t]==x) return ;
return F[x]=min(solve(x-f[t-]),solve(f[t]-x))+;
}
int main()
{
f[]=; f[]=;
for (int i=; f[i-]<=inf; i++,top++) f[i]=f[i-]+f[i-];
P=ra();
for (int i=; i<=P; i++)
printf("%d\n",solve(ra()));
return ;
}
bzoj 2796: [Poi2012]Fibonacci Representation的更多相关文章
- BZOJ [Poi2012]Fibonacci Representation
找最近的数 记忆化 (我也不知道为什么对的) #include<cstdio> #include<algorithm> #include<map> using na ...
- BZOJ2796[Poi2012]Fibonacci Representation——贪心+二分查找
题目描述 给出一个正整数x,问x最少能由多少个Fibonacci数加减算出. 例如1070=987+89-5-1,因此x=1070时答案是4. 输入 第一行一个正整数q (q<=10),表示有q ...
- 【bzoj2796】 [Poi2012]Fibonacci Representation
给出一个数字,用FIB数列各项加加减减来得到. 问最少要多少个(可以重复使用) 大概试了一下,fibonacci数列的增长是很快的,大概到了90+项就超过了题目范围…… 所以每次找一个最近的fibon ...
- [BZOJ2796][Poi2012]Fibonacci Representation
由于是斐波那契数列,所以$x_i+x_j<=x_k,i<j<k$ 所以猜测可以贪心选择两边近的数处理. #include<cstdio> #include<algo ...
- 洛谷 P3539 [POI2012]ROZ-Fibonacci Representation 解题报告
P3539 [POI2012]ROZ-Fibonacci Representation 题意:给一个数,问最少可以用几个斐波那契数加加减减凑出来 多组数据10 数据范围1e17 第一次瞬间yy出做法, ...
- Bzoj 2789: [Poi2012]Letters 树状数组,逆序对
2789: [Poi2012]Letters Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 278 Solved: 185[Submit][Stat ...
- P3539 [POI2012]ROZ-Fibonacci Representation
题目描述 The Fibonacci sequence is a sequence of integers, called Fibonacci numbers, defined as follows: ...
- BZOJ 2795: [Poi2012]A Horrible Poem( hash )
...字符串hash. 假如长度x是一个循环节, 那么对于任意n(x | n)也是一个循环节. 设当前询问区间[l, r]长度为len = ∏piai, 最终答案ans = ∏piai' ,我们只需枚 ...
- BZOJ 2789: [Poi2012]Letters( BIT )
直接求逆序对就行了...时间复杂度O(nlogn) ------------------------------------------------------------------------- ...
随机推荐
- error C2664: “FILE *fopen(const char *,const char *)”: 无法将参数 1 从“LPCTSTR”转换为“const char *”
遇到这个问题,请打开本项目的Properties(属性)-------> Configuration Properties(配置属性)-------->General(常规)------- ...
- 136、Java的内部类
01.代码如下: package TIANPAN; class Outer { // 外部类 private String msg = "Hello World !"; class ...
- Centos7 VNC远程桌面服务安装配置
1.服务器版本 CentOS Linux release 7.7.1908 (Core) 首先系统安装了GUI界面 # ln -sf /lib/systemd/system/graphical.tar ...
- AngularJS 官方启动文档
参考:https://angular.io/guide/quickstart 中文:http://www.angularjs.net.cn/
- java并发初探CyclicBarrier
java并发初探CyclicBarrier CyclicBarrier的作用 CyclicBarrier,"循环屏障"的作用就是一系列的线程等待直至达到屏障的"瓶颈点&q ...
- vue - 封装input
input子组件 <el-input :value="value" placeholder="请输入内容" size="small" ...
- 修饰者模式(装饰者模式,Decoration)
1. 装饰者模式,动态地将责任附加到对象上.若要扩展功能,装饰者提供了比继承更加有弹性的替代方案. 2.组合和继承的区别 继承.继承是给一个类添加行为的比较有效的途径.通过使用继承,可以使得子类在拥有 ...
- nodejs(12)Express 中间件middleware
中间件 客户端的请求到达服务器时,他的生命周期是:request -- 服务器端处理 -- 响应 在服务器端处理过程中,业务逻辑复杂时,为了便于开发维护,需要把处理的事情分成几步,这里每一步就是一个中 ...
- asp.net获取时间日期插入数据库
//获取日期+时间 DateTime.Now.ToString(); // 2008-9-4 20:02:10 DateTime.Now.ToLocalTime().ToString(); // 20 ...
- SpringBoo-Thymeleaf
SpringBoo-Thymeleaf SpringBoo-Thymeleaf简介 SpringBoot并不推荐使用JSP,它推荐我们使用模板引擎Thymeleaf,它与Velocity.Free ...