二分 Codeforces633D Fibonacci-ish
来源:互联网 发布:淘宝客服需要做些什么 编辑:程序博客网 时间:2024/05/05 20:16
传送门:点击打开链接
题意:找出最长的斐波那契数列,f0和f1可以是出现的数字里的任何数
思路:枚举f0和f1,根据斐波那契的收敛性,我们能顺着去判断出最长有多长,注意要特判掉f0和f1都等于0的情况,不然复杂度会退化到O(n^3)
刚开始是用map,然后T了,其实用数组搞一搞就行了,这里用了一种很傻逼的写法来清空数组,和线段树的懒惰标记很类似
#include<map>#include<set>#include<cmath>#include<ctime>#include<stack>#include<queue>#include<cstdio>#include<cctype>#include<string>#include<vector>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#define fuck(x) cout<<"["<<x<<"]"#define FIN freopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w+",stdout)using namespace std;typedef long long LL;const int MX = 1e3 + 5;const int INF = 0x3f3f3f3f;const int mod = 1e9 + 7;int cnt[MX], sign[MX];int A[MX], B[MX], C[MX], sz = 0;int ID(int x) { int l = 1, r = sz, m; while(l <= r) { m = (l + r) >> 1; if(C[m] == x) return m; if(C[m] < x) l = m + 1; else r = m - 1; } return 0;}bool check(int p, int tim) { if(sign[p] != tim) { sign[p] = tim; cnt[p] = 0; } return true;}int main() { //FIN; int n; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &A[i]); } sort(A + 1, A + 1 + n); for(int l = 1, r; l <= n; l = r + 1) { for(r = l; r + 1 <= n && A[r + 1] == A[r]; r++); C[++sz] = A[l]; B[sz] = r - l + 1; } int ans = max(B[ID(0)], 2); for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(i == j || (!A[i] && !A[j])) continue; int f0 = A[i], f1 = A[j], f2 = f0 + f1, id = ID(f2), now = 2; int id1 = ID(A[i]), id2 = ID(A[j]), tim = i * n + j; check(id1, tim); check(id2, tim); cnt[id1]++; cnt[id2]++; while(id && check(id, tim) && cnt[id] + 1 <= B[id]) { sign[id] = i * n + j; cnt[id]++; now++; f0 = f1; f1 = f2; f2 = f0 + f1; id = ID(f2); } ans = max(ans, now); } } printf("%d\n", ans); return 0;}
0 0
- 二分 Codeforces633D Fibonacci-ish
- codeforces633D Fibonacci-ish map容器
- 【CF633D】Fibonacci-ish
- 【Codeforces633H】Fibonacci-ish II
- Codeforces 633D Fibonacci-ish(搜索)
- Codeforces 633D Fibonacci-ish 【暴力递归】
- Codeforces 633D Fibonacci-ish(暴力)
- CodeForces - 633D Fibonacci-ish (map&暴力)
- Manthan, Codefest 16 D. Fibonacci-ish
- Manthan, Codefest 16-D. Fibonacci-ish
- Codeforces 633D Fibonacci-ish 数学+暴力
- CodeForces 633 D.Fibonacci-ish(枚举)
- Manthan, Codefest 16 D. Fibonacci-ish(暴力、规律)
- Manthan, Codefest 16 633D Fibonacci-ish(脑洞+stl)
- Manthan, Codefest 16 D. Fibonacci-ish(暴力)
- CodeForces 633D Fibonacci-ish(容器暴力)
- Manthan, Codefest 16 H. Fibonacci-ish II (暴力)
- Codeforces633D【暴力】
- volley的用法(数据库网络请求框架 )
- 2016-2-27补写
- window 窗口对象 - Javascript语言描述
- swift 电子书阅读器
- 个人进阶之路——自定义控件(6)
- 二分 Codeforces633D Fibonacci-ish
- ios之下载进度条和雪花下落的功能实现
- 合并两个排序的列表
- 232. Implement Queue using Stacks
- html中的锚点笔记
- flock导致进程卡死, 如何查看
- MVC+WCF实现一条线对应的改动
- poj 2785 4 Values whose Sum is 0
- CSS小技巧总结