当前位置:网站首页>[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 ;
}
边栏推荐
- Overflow: the combination of auto and Felx
- 昆明三环闭合工程将经过这些地方,有在你家附近的吗?
- Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
- Research Report on market supply and demand and strategy of China's plastics and polymer industry
- Can you really use MySQL explain?
- 安信证券网上开户安全吗 开户收费吗
- Research Report of exoskeleton robot industry - market status analysis and development prospect prediction
- Array filter fliter in JS
- Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
- Transformer中position encoding实践
猜你喜欢
NoSQL之readis配置与优化(终章)
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
多年锤炼,迈向Kata 3.0 !走进开箱即用的安全容器体验之旅| 龙蜥技术
Principle and general steps of SQL injection
照明行业S2B2B解决方案:高效赋能产业供应链,提升企业经济效益
Transformer中position encoding实践
The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
The test experience "tortured" by the PMP test is worth your review
Readis configuration and optimization of NoSQL (final chapter)
随机推荐
Research Report on surgical otorhinolaryngology equipment industry - market status analysis and development prospect prediction
[Acwing] 58周赛 4489. 最长子序列
GO开发:如何利用Go单例模式保障流媒体高并发的安全性?
Height residual method
Research Report on market supply and demand and strategy of tetramethylpyrazine industry in China
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
How to decrypt worksheet protection password in Excel file
安信证券手机版下载 网上开户安全吗
overflow:auto与felx结合的用法
基于wifi控制的51单片机温度报警器
Overflow: the combination of auto and Felx
The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
C# 更加优质的操作MongoDB数据库
Lv166 turned over
C # realizes FFT forward and inverse transformation and frequency domain filtering
Practice: fabric user certificate revocation operation process
C# 服务器日志模块
NoSQL之readis配置与优化(终章)
ECCV 2022放榜了:1629篇论文中选,录用率不到20%
程序员怎么才能提高代码编写速度?