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以内的 ...
随机推荐
- JS获取照片拍摄的角度属性,用于旋转控制
我工作十余年,从负责一个模块,到负责一个产品,再到负责整个支付平台的架构设计,包括业务架构.产品架构到应用架构,再到技术架构,是一个从点到面逐渐转型的过程,同样是个“自相似”的现象,我一开始写博客,再 ...
- The Cave
The Cave 题目描述 给定一棵有n个节点的树,相邻两点之间的距离为1. 请找到一个点x,使其满足所有m条限制,其中第i条限制为dist(x,a[i])+dist(x,b[i])<=d[i] ...
- 经典 Javascript 正则表达式
正则表达式用于字符串处理,表单验证等场合,实用高效,但用到时总是不太把握,以致往往要上网查一番.我将一些常用的表达式收藏在这里,作备忘之用.匹配中文字符的正则表达式: }
- Spring中报"Could not resolve placeholder"的解决方案(引入多个properties文件)
除去properites文件路径错误.拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderCon ...
- OPEN SUSE LINUX
1. 把中文界面变成英文界面 yast2->system->language: 主要语言: 美式英语US 2. 使用root用户默认登录 Ubuntu使用root登录 Ubu ...
- 关闭 C4996 警告(_CRT_SECURE_NO_DEPRECATE)
在使用VC 2005 的开发者会遇到这样的问题,在使用std命名空间库函数的时候,往往会出现类似于下面的警告: warning C4996: strcpy was declared deprecate ...
- Xdebug安装对应版本与配置
Xdebug安装地址https://xdebug.org/download.php,进入下载页面后点击custom installation instructions,可以找到适合的Xdebug版本. ...
- python--math
>>> import math >>> >>> # ceil,取大于等于x的最小的整数值 >>> math.ceil(4) 4 ...
- python的优化机制与垃圾回收与gc模块
python属于动态语言,我们可以随意的创建和销毁变量,如果频繁的创建和销毁则会浪费cpu,那么python内部是如何优化的呢? python和其他很多高级语言一样,都自带垃圾回收机制,不用我们去维护 ...
- Codeforces Round #377 (Div. 2) A. Buy a Shovel【暴力/口袋里面有无限枚 10 元和一枚 r 面值的硬币,问最少可以买多少把价值为 k 的铁铲】
A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...