当前位置:网站首页>[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 ;
}
边栏推荐
- Research Report on market supply and demand and strategy of China's four sided flat bag industry
- . Net applications consider x64 generation
- Task state rollback and data blocking tasks based on check point mechanism
- Market trend report, technical innovation and market forecast of tetrabromophthalate (pht4 diol) in China
- 智慧物流園區供應鏈管理系統解决方案:數智化供應鏈賦能物流運輸行業供應鏈新模式
- 如何实现一个延时队列 ?
- Spark 中的 Rebalance 操作以及与Repartition操作的区别
- I let the database lock the table! Almost fired!
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- 最大子数组与矩阵乘法
猜你喜欢

Yanwen logistics plans to be listed on Shenzhen Stock Exchange: it is mainly engaged in international express business, and its gross profit margin is far lower than the industry level

S2b2b solution for lighting industry: efficiently enable the industrial supply chain and improve the economic benefits of enterprises

Embedded software architecture design - function call

VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题

照明行业S2B2B解决方案:高效赋能产业供应链,提升企业经济效益

DC-2靶场搭建及渗透实战详细过程(DC靶场系列)

Visual Studio 2019 (LocalDB)MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782

overflow:auto与felx结合的用法

Transformer中position encoding实践

昆明三环闭合工程将经过这些地方,有在你家附近的吗?
随机推荐
How to contribute to the source code of ongdb core project
Four point probe Industry Research Report - market status analysis and development prospect prediction
Opencv learning -- arithmetic operation of image of basic operation
安信证券网上开户安全吗 开户收费吗
PyTorch深度学习快速入门教程
Cut! 39 year old Ali P9, saved 150million
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业
Jump table instance
Li Kou today's question -1200 Minimum absolute difference
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
overflow:auto与felx结合的用法
Start by counting
.Net 应用考虑x64生成
时序图数据建模与产业链分析
Median and order statistics
The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
I let the database lock the table! Almost fired!
GO开发:如何利用Go单例模式保障流媒体高并发的安全性?
如何为ONgDB核心项目源码做贡献
Array filter fliter in JS