Manthan, Codefest 16 D. Fibonacci-ish(暴力)

题目链接:点击打开链接

题意:给你n个数, 问最长的题目中定义的斐波那契数列。 

思路:枚举開始的两个数, 由于最多找90次, 所以能够直接暴力, 用map去重。  注意, 该题卡的时间有点厉害啊。 用了两个map结果超时。

细节參见代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define Max(a,b) ((a)>(b)?

(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) using namespace std; typedef long long ll; typedef long double ld; const ld eps = 1e-9, PI = 3.1415926535897932384626433832795; const int mod = 1000000000 + 7; const int INF = int(1e9); const ll INF64 = ll(1e18); const int maxn = 1000 + 10; int T,n,m; ll a[maxn], b[maxn]; map<ll, int> p, bit; int main() { scanf("%d",&n); int cnt0 = 0; for(int i=0;i<n;i++) { scanf("%I64d",&a[i]); p[a[i]]++; if(!a[i]) ++cnt0; } int ans = 2; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i == j) continue; if(!a[i] && !a[j]) { ans = max(ans, cnt0); continue; } else { int cur = 2, cnt = 2; ll l = a[i], r = a[j]; b[0] = l; b[1] = r; while(abs(l + r) <= INF) { b[cnt++] = l + r; ll c = r; r = l + r; l = c; } b[cnt++] = l + r; for(int k = 0; k < cnt; k++) { if(!p.count(b[k]) || p[b[k]] == 0) { ans = max(ans, k); for(int l = 0; l < k; l++) p[b[l]]++; break; } else p[b[k]]--; } } } } printf("%d\n",ans); return 0; }



posted @ 2018-03-31 16:55  zhchoutai  阅读(101)  评论(0编辑  收藏  举报