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;
}
Manthan, Codefest 16 D. Fibonacci-ish(暴力)的更多相关文章
- Manthan, Codefest 16 D. Fibonacci-ish 暴力
D. Fibonacci-ish 题目连接: http://www.codeforces.com/contest/633/problem/D Description Yash has recently ...
- Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵
H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...
- Manthan, Codefest 16 D. Fibonacci-ish
D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard in ...
- Manthan, Codefest 16 -A Ebony and Ivory
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Manthan, Codefest 16
暴力 A - Ebony and Ivory import java.util.*; import java.io.*; public class Main { public static void ...
- Manthan, Codefest 16 A. Ebony and Ivory 水题
A. Ebony and Ivory 题目连接: http://www.codeforces.com/contest/633/problem/A Description Dante is engage ...
- 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 ...
- Manthan, Codefest 16 -C. Spy Syndrome 2
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- CF Manthan, Codefest 16 G. Yash And Trees 线段树+bitset
题目链接:http://codeforces.com/problemset/problem/633/G 大意是一棵树两种操作,第一种是某一节点子树所有值+v,第二种问子树中节点模m出现了多少种m以内的 ...
随机推荐
- 【计算机网络基础】用 telnet 检查 VPS 的某个端口是否处于监听状态
命令 telnet x.x.x.x p 其中 x.x.x.x 代表 VPS 的 IP 地址,p 代表要检查的端口号. 起因是我的 ss 不好使了.IP 没被封,查了一下,可能是 ssserver 的端 ...
- [hdu6432]Problem G. Cyclic
题目大意:给你$n$,一种合法的排列为,排列中没有$s[i\%n+1]-s[i]==1$,求合法方案数 题解:容斥,令$f_{i,j}$表示有$i$个元素,至少包含$j$个$s[i\%n+1]-s[i ...
- 【普通の惨败】GDOI2015卖萌记
前记:这次可真的全程卖萌了.... Day 0 早早坐上前往广州的火车,然后转车到韶关 然后就到了偏远郊区的(准)四星酒店 周围连路灯都没有,极其僻静极其荒凉 大家都极其安静地回到自己房间复习 这一天 ...
- BZOJ 1208 [HNOI2004]宠物收养所 | SPlay模板题
题目: 洛谷也能评 题解: 记录一下当前树维护是宠物还是人,用Splay维护插入和删除. 对于任何一次询问操作都求一下value的前驱和后继(这里前驱和后继是可以和value相等的),比较哪个差值绝对 ...
- gcc 编译器常用的命令行参数一览
这些常用的 gcc/g++ 命令行参数,你都知道么? 1. gcc -E source_file.c -E,只执行到预编译.直接输出预编译结果. 2. gcc -S source_file.c -S, ...
- linux系统——ld-linux.so.X查找和加载共享动态库的顺序
ld-linux.so查找共享库的顺序: Glibc安装的库中有一个为ld-linux.so.X,其中X为一个数字,在不同的平台上名字也会不同.可以用ldd查看: #ldd /bin/cat linu ...
- C/C++ 运算符 & | 运算
C/C++中的“按位或 规则: 1|1=1 1|0=1 0|1=1 0|0=0 按位或运算 按位或运算符“|”是双目运算符.其功能是参与运算的两数各对应的二进位(也就是最后一位)相或.只要对应的二个二 ...
- 今天做一个winform,想直接把窗体改成输出类库,其他地方直接调结果总提示不能注册组件,回来调度,可以,总结,windows还是直接用新建的类型项目,改容易出错
如题, 对于winform程序,还是新建一个类库,这样,在类库里面可以添加窗体.这样可以提供其他程序集来调用里面的窗体
- 漂亮的弹窗口插件——sweetAlert的使用
想必你已经受够了单调的alert弹窗吧? 为了更好的用户体验性,现在介绍一款漂亮的弹窗口插件——sweetAlert,现在就来介绍它的使用 1.首先在官网下载它的CSS和JavaScript文件:ht ...
- 关于JAVA SESSION的小测试
手生就要多练啊... package com.jeelearning.servlet; import java.io.IOException; import java.io.PrintWriter; ...