Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1609 Accepted Submission(s): 411
题目大意:
中文题能看懂就不说意思了
斐波那契数列
f[0]=0;f[1]=1;
f[i]=f[i-1]+f[i-2];
上代码
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; #define N 10005 int fei[N]; int f[N]; int Find(int x) { if(x!=f[x]) f[x]=Find(f[x]); return f[x]; } int main() { int Maxn; fei[0]=1; fei[1]=2; for(int i=2;fei[i-1]<1000000000;i++) { fei[i]=fei[i-1]+fei[i-2]; Maxn=i; } int n,m,k,u,v,r[N]; while(scanf("%d %d",&n,&m)!=EOF) { memset(r,0,sizeof(r)); for(int i=1;i<=n;i++) { f[i]=i; scanf("%d",&k); int index=lower_bound(fei,fei+Maxn,k)-fei; if(fei[index]==k) r[i]++; } for(int i=0;i<m;i++) { scanf("%d %d",&u,&v); int fu=Find(u); int fv=Find(v); if(fu!=fv) { f[fu]=fv; r[Find(fu)]=r[fu]+r[fv]; } } int Max=0; for(int i=1;i<=n;i++) { if(f[i]==i) Max=max(Max,r[i]); } printf("%d\n",Max); } return 0; }
原文:http://www.cnblogs.com/linliu/p/5005279.html