【题目】
【题解】
题意:给定一个递增的序列,构造一个后一项不大于前一项的两倍的最长子序列(可不连续),输出长度。
思路:虽然题意说是构造的子序列可不连续,但是因为原始序列具有单调性,所以肯定是连续的,所以我们只需要比较每一段符合要求的子序列的长度即可。
【代码】
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#define mem(a) memset(a,0,sizeof(a))
#define go(i,a,b) for(int i=a;i<=b;i++)
#define og(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
typedef long long ll;
typedef unsigned long long ull;
main()
{
int n,a[2*maxn],dp[2*maxn];
scanf("%d",&n);
go(i,1,n) scanf("%d",&a[i]);
int l=1,ans=1;dp[1]=a[1];
go(i,2,n)
{
if(a[i]<=dp[l]*2) dp[++l]=a[i];
else
{
ans=max(ans,l);
l=1;
dp[l]=a[i];
}
}
ans=max(ans,l);
printf("%d\n",ans);
}