题目链接:点击打开链接

题意:给你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. BZOJ2535 [Noi2010]Plane 航空管制 【贪心 + 堆】

    题目链接 BZOJ2535 题解 航班之间的关系形成了一个拓扑图 而且航班若要合法,应尽量早出发 所以我们逆拓扑序选点,能在后面出发的尽量后面出发,不会使其它点变得更劣,容易知是正确的 第二问只需枚举 ...

  2. 【POJ 2387 Til the Cows Come Home】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 59755Accepted: 20336 Description Bessie is ...

  3. bzoj1861 [Zjoi2006]Book 书架 splay

    小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书,看完后放回书柜然后再拿下一本.由于这些书太有吸引 ...

  4. 让Vs2010支持 Css3+HTML5

    第一步. 先到微软官方下载一个 Microsoft Visual Studio 2010 sp1 . 给传送门:.microsoft.com/downloads/zh-cn/details.aspx? ...

  5. 汕头市队赛 SRM10 T3 数学上来先打表

    数学上来先打表 SRM 10 描述 给出 n个点(不同点之间有区别),求出满足下列条件的连边(双向边)方案:1.每条边连接两个不同的点,每两个点之间至多有一条边2.不存在三个点a,b,c使三个点间两两 ...

  6. java IO的字节流和字符流及其区别

    1. 字节流和字符流的概念    1.1 字节流继承于InputStream    OutputStream,    1.2 字符流继承于InputStreamReader    OutputStre ...

  7. 行为型设计模式之迭代器模式(Iterator)

    结构 意图 提供一种方法顺序访问一个聚合对象中各个元素, 而又不需暴露该对象的内部表示. 适用性 访问一个聚合对象的内容而无需暴露它的内部表示. 支持对聚合对象的多种遍历. 为遍历不同的聚合结构提供一 ...

  8. 转载: CentOS/Linux 解决 SSH 连接慢

    CentOS/Linux 解决 SSH 连接慢 现在连接Linux服务器一般都是使用SSH远程连接的方式.最近新装了一台服务器,发现telnet时速度很快,ping时一切也正常,但SSH连接的时候却很 ...

  9. (转)vim 常用快捷键 二

    转自:http://www.cnblogs.com/wangkangluo1/archive/2012/04/12/2444952.html 键盘移动 (Move) 一切都从键盘的移动 k -> ...

  10. OpenGL入门学习(三)

    http://developer.178.com/201103/94954704639.html 在第二课中,我们学习了如何绘制几何图形,但大家如果多写几个程序,就会发现其实还是有些郁闷之处.例如:点 ...