题目描述 给出一个正整数x,问x最少能由多少个Fibonacci数加减算出. 例如1070=987+89-5-1,因此x=1070时答案是4. 输入 第一行一个正整数q (q<=10),表示有q组输出. 下面q行每行一个正整数x (x<=4*10^17). 输出 输出q行,依次表示每个输出的答案. 样例输入 1 1070 样例输出 4   因为f[i]=f[i-1]+f[i-2],f[i+1]=f[i]+f[i-1],能得到2f[i]=f[i+1]+f[i-2],所以最优答案一定存在没有一个F…
由于是斐波那契数列,所以$x_i+x_j<=x_k,i<j<k$ 所以猜测可以贪心选择两边近的数处理. #include<cstdio> #include<algorithm> #define ll long long #define mid (l+r>>1) using namespace std; ll f[],tot=; inline ll findl(ll x) { ,r=tot,ans=; while(l<=r) { ; ; } ret…
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每次还要和an比较 注意:不能选取两个相同的数 反思:比赛时想到了%p和sort,lower_bound,但是还是没有想到这个贪心方法保证得出最大值,还是题目做的少啊:( */ #include <cstdio> #include <algorithm> #include <cst…
The link to problem:Problem - D - Codeforces   D. Range and Partition  time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Given an array a of n integers, find a range of values [x,y] (x≤y…
给出一个数字,用FIB数列各项加加减减来得到. 问最少要多少个(可以重复使用) 大概试了一下,fibonacci数列的增长是很快的,大概到了90+项就超过了题目范围…… 所以每次找一个最近的fibonacci数试一下就好,实测跑得飞快. #include<bits/stdc++.h> using namespace std; typedef long long ll; ll f[],n,m; inline ll read(){ ll f=,x=;char ch; ;}'); +ch-'); r…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1065    Accepted Submission(s): 536 Problem Description Today, bes…
结论貌似是,,,肯定只有没有重复的数字.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…
找最近的数 记忆化 (我也不知道为什么对的) #include<cstdio> #include<algorithm> #include<map> using namespace std; int q,lim=85,id; long long F[105]; map<long long,int> M; int dfs(long long x){ if (M[x]) return M[x]; int id1=lower_bound(F+1,F+lim+1,x)…
大意: 给定数$n$, 求将$n$划分为最少的斐波那契数的和或差. 每次取相邻$n$的斐波那契数一定最优, 考虑证明. 结论1:存在一个最优解,使得每个斐波那契数使用不超过1次.(考虑$2F_n=F_{n-2}+F_{n+1}$) 结论2:存在一个最优解,使得同号数不相邻, 异号数间隔$\ge 2$. 根据结论1和2, 假设最优解所选最大斐波那契数为$F_k$, 那么 $n$的下界为$F_k-F_{k-3}-F_{k-5}-...$, $k$为奇时为$F_{k-1}$, $k$为偶时为$F_{k…
抄书  (二分查找+贪心) 提示:二分查找一般写成非递归形式 时间复杂度:O(logn) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/B Description   Copying Books Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had…