题目链接:点击打开链接

题意:给你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;
}

Manthan, Codefest 16 D. Fibonacci-ish(暴力)的更多相关文章

  1. Manthan, Codefest 16 D. Fibonacci-ish 暴力

    D. Fibonacci-ish 题目连接: http://www.codeforces.com/contest/633/problem/D Description Yash has recently ...

  2. Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵

    H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...

  3. Manthan, Codefest 16 D. Fibonacci-ish

    D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard in ...

  4. Manthan, Codefest 16 -A Ebony and Ivory

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  5. Manthan, Codefest 16

    暴力 A - Ebony and Ivory import java.util.*; import java.io.*; public class Main { public static void ...

  6. Manthan, Codefest 16 A. Ebony and Ivory 水题

    A. Ebony and Ivory 题目连接: http://www.codeforces.com/contest/633/problem/A Description Dante is engage ...

  7. Manthan, Codefest 16(B--A Trivial Problem)

    B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. Manthan, Codefest 16 -C. Spy Syndrome 2

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. CF Manthan, Codefest 16 G. Yash And Trees 线段树+bitset

    题目链接:http://codeforces.com/problemset/problem/633/G 大意是一棵树两种操作,第一种是某一节点子树所有值+v,第二种问子树中节点模m出现了多少种m以内的 ...

随机推荐

  1. BZOJ5299 [Cqoi2018]解锁屏幕 【状压dp】

    题目链接 BZOJ5299 题解 就一个毒瘤卡常题..写了那么久 设\(f[i][s]\)表示选了集合\(s\)中的点,最后一个是\(i\),进行转移 要先预处理出两点间的点,然后卡卡常就可以过了 # ...

  2. springMvc <form:form>标签 <form:input>标签需要注意的问题

    在用springMVC <form:form>表单时,喜欢报的错误如下所示: 错误的Controller层的代码如下: @RequestMapping(value = "test ...

  3. Windows域同步检查repadmin

    C:\Users\>repadmin /show replUsage: repadmin <cmd> <args> [/u:{domain\user}] [/pw:{pa ...

  4. JSONP原理小记

    大家都知道JSONP(JSON with padding参数式JSON)是跨域传输数据的方法,jq等很多类库都封装了JSONP的方法,但是他的原理是怎样的呢?下面举个我认为最浅显的栗子,大家看过了都会 ...

  5. wordpress对使用的国外主题进行本地汉化

    wordpress有非常多优秀与专业的主题,当然大多数是非中文的 这些主题本身总会有些无法通过wordpress admin后台来配置的在页面上的英文输出 此时你可以去对应的代码去改掉那些输出,不过这 ...

  6. mysql 游标的嵌套使用示例

    BEGIN DECLARE trainee_no_value BIGINT (20); -- 学员编号 DECLARE pay_no_value BIGINT (20); -- 交费序号 DECLAR ...

  7. Linux进程管理与调度-之-目录导航【转】

    转自:http://blog.csdn.net/gatieme/article/details/51456569 版权声明:本文为博主原创文章 && 转载请著名出处 @ http:// ...

  8. electron 安装使用

    1.安装 node.js 链接:http://pan.baidu.com/s/1o7W7BIy 密码:y6od 一路next 我安装在F:\Program Files\node.js下 2.检查nod ...

  9. DropZone图片上传控件的使用

    前台代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w ...

  10. pymongo: MongoClient opened before fork错误排解

    使用pymongo配合flask和gunicorn使用的时候触发以下错误信息: [2017-09-19 15:20: ] [25780] [CRITICAL] WORKER TIMEOUT (pid: ...