当前位置:网站首页>[acwing] 58 weeks 4489 Longest subsequence
[acwing] 58 weeks 4489 Longest subsequence
2022-07-04 17:01:00 【*DDL_ GzmBlog】
Preface
t a g : tag : tag: thinking
Portal :
The question :
Given a rising Array of , Find a subsequence so that the elements in the subsequence meet a j ∗ 2 ≥ a j + 1 a_j*2\ge a_{j+1} aj∗2≥aj+1, Ask about the sequence of legitimate subsequences Maximum length
Ideas :
Because the given array is ascendant
So if a 1 ∗ 2 ≥ a 3 a_1*2\ge a_3 a1∗2≥a3 There is , Then there must be a 1 ∗ 2 ≥ a 2 a_1 *2\ge a_2 a1∗2≥a2
Then this condition makes the answer continuity , So we just need O n On On Just sweep it once
code :
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
#define IOS ios::sync_with_stdio(false);
#define CIT cin.tie(0);
#define COT cout.tie(0);
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),x.end()
#define Fup(i,a,b) for(int i=a;i<=b;i++)
#define Fde(i,a,b) for(int i=a;i>=b;i--)
#define cer(a) cerr<<#a<<'='<<(a)<<" @ line "<<__LINE__<<" "<<endl
typedef priority_queue<int,vector<int>,greater<int>> Pri_m;
typedef pair<int,int> pii;
typedef vector<int> VI;
map<int,int> mp;
const int N = 2e5+10,INF = 0x3f3f3f3f;
const double eps = 1e-5;
struct node{
int to,val;
};
int a[N],st[N];
int n,i;
void solve(){
cin>>n;
int ans = -INF;
Fup(i,1,n) cin>>a[i];
int res = 1;
Fup(i,1,n-1){
if(a[i]*2 >= a[i+1]) res++;
else res = 1;
ans = max(ans,res);
}
cout<<ans<<endl;
// Fup(i,1,n-1) if(a[i]*2 >= a[i+1]) st[i] = 1;
// Fup(i,1,n-1){
// if( !st[i] ) continue;
// int res = 1;
// while(st[i]) i ++ , res++;
// ans = max(res,ans);
// }
// if(ans < 0 ) cout<<1<<endl;
// else cout<<ans<<endl;
}
int main(){
//int t;cin>>t;while(t--)
solve();
return 0 ;
}
边栏推荐
- tp配置多数据库
- Li Kou today's question -1200 Minimum absolute difference
- Task state rollback and data blocking tasks based on check point mechanism
- ~89 deformation translation
- Is it safe for Anxin securities to open an account online? Is the account opening fee charged
- 周大福践行「百周年承诺」,真诚服务推动绿色环保
- 一图看懂ThreadLocal
- System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
- [glide] cache implementation - memory and disk cache
- Median and order statistics
猜你喜欢

如何实现一个延时队列 ?

Congratulations to Mr. Zhang Pengfei, chief data scientist of artefact, for winning the campaign Asia tech MVP 2022

对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平

Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782

The winning rate against people is 84%, and deepmind AI has reached the level of human experts in army chess for the first time

多年锤炼,迈向Kata 3.0 !走进开箱即用的安全容器体验之旅| 龙蜥技术
Can you really use MySQL explain?

Position encoding practice in transformer

Smart Logistics Park supply chain management system solution: digital intelligent supply chain enables a new supply chain model for the logistics transportation industry

~88 running people practice
随机推荐
世界环境日 | 周大福用心服务推动减碳环保
Market trend report, technical innovation and market forecast of taillight components in China
C# 更加优质的操作MongoDB数据库
Start by counting
Opencv learning -- geometric transformation of image processing
Li Kou today's question -1200 Minimum absolute difference
Hash table
安信证券排名 网上开户安全吗
Research Report on market supply and demand and strategy of China's Sodium Tetraphenylborate (cas+143-66-8) industry
Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
Sequence diagram data modeling and industrial chain analysis
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平
"Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
Accounting regulations and professional ethics [6]
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
Market trend report, technical innovation and market forecast of China's hair repair therapeutic apparatus
Maximum subarray and matrix multiplication