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以内的 ...
随机推荐
- CF992E Nastya and King-Shamans 解题报告
CF992E Nastya and King-Shamans 题意翻译 给定一个序列 \(a_i\),记其前缀和序列为 \(s_i\),有 \(q\) 个询问,每次单点修改,询问是否存在一个 \(i\ ...
- SQL的主键和外键的作用
SQL的主键和外键约束 转载自:http://www.cnblogs.com/ywb-lv/archive/2012/03/12/2391860.html感谢原文作者的总结 SQL的主键和外键的作用: ...
- 理解javascript的闭包,原型,和匿名函数及IIFE
理解javascript的闭包,原型,和匿名函数(自己总结) 一 .>关于闭包 理解闭包 需要的知识1.变量的作用域 例1: var n =99; //建立函数外的全局变量 function r ...
- Sublime Text3 注册码激活码(持续更新中2018-11-20)
Sublime Text 3的注册码 个人记录,便于查找 谢谢各位的认可 11.20版本 ----- BEGIN LICENSE ----- sgbteam Single User License E ...
- dedeCMS常用功能板块记忆
1.自动调到栏目第一个子栏目 <script> {dede:channel type='son' row='1'} window.location.href='[field:typelin ...
- android studio 无法调试debug,(能运行安装)
请检查清单文件的改为true就可以调试了 android:debuggable="true"
- Kubernetes-服务发布
#发布服务有三种方式,第一种把端口映射到所有节点比较适合发布一些tcp/udp的服务对于应用层像http的会导致无法获取到原始客户端IP,第二种需要用到云服务才行,第三种是ingress http服务 ...
- Kubernetes DNS安装配置
#镜像在谷歌上需要FQ###################################下载kubernetes#DNS#cd kubernetes/cluster/addons/dns#修改tr ...
- 判断dataset是否被修改—DataSet.HasChanges 方法
DataSet.HasChanges 方法 获取一个值,该值指示 DataSet 是否有更改,包括新增行.已删除的行或已修改的行. 命名空间: System.Data程序集: System.Da ...
- 我从16ASPX上下了一个程序在运行时出错是怎么回事?运行时出现用户SA登陆失败,但是我已经把数据库导入SQL
如果你账号密码正确,那你可能没有打开你的管线服务,或者没有配置好你的客户端