zoukankan      html  css  js  c++  java
  • 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 ",ans); return 0; }



  • 相关阅读:
    POJ 3635 Full Tank?
    ZOJ 2112 Dynamic Rankings
    POJ 3468 A Simple Problem with Integers (2)
    FJOI2007 轮状病毒
    HDU 3308 LCIS
    POJ 2449 Remmarguts' Date
    Adroid平台图表案例源码
    Android项目——实现时间线程源码
    关于Ubuntu上Eclipse不显示手机设备
    自定义ListView下拉弹起效果
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8682965.html
Copyright © 2011-2022 走看看