当前位置:网站首页>[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 ;
}
边栏推荐
- Firebird experience summary
- NoSQL之readis配置与优化(终章)
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- Accounting regulations and professional ethics [7]
- How to contribute to the source code of ongdb core project
- APOC自定义函数和过程
- [Acwing] 58周赛 4489. 最长子序列
- How to implicitly pass values when transferring forms
- Use and principle of thread pool
- ~89 deformation translation
猜你喜欢

《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下

Object. Usage of keys()

周大福践行「百周年承诺」,真诚服务推动绿色环保

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

DIY a low-cost multi-functional dot matrix clock!

祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022

昆明三环闭合工程将经过这些地方,有在你家附近的吗?

Transformer中position encoding实践

51 single chip microcomputer temperature alarm based on WiFi control

L1-072 scratch lottery
随机推荐
Can you really use MySQL explain?
Firebird experience summary
Integration of ongdb graph database and spark
Implement graph data construction task based on check point
Go语言循环语句(第10课下)
昆明三环闭合工程将经过这些地方,有在你家附近的吗?
Opencv learning -- arithmetic operation of image of basic operation
China's plastic processing machinery market trend report, technological innovation and market forecast
Task state rollback and data blocking tasks based on check point mechanism
PyTorch深度学习快速入门教程
C # realizes FFT forward and inverse transformation and frequency domain filtering
S2b2b solution for lighting industry: efficiently enable the industrial supply chain and improve the economic benefits of enterprises
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Hair and fuzz interceptor Industry Research Report - market status analysis and development prospect forecast
基于wifi控制的51单片机温度报警器
Research Report on market supply and demand and strategy of China's well completion equipment industry
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
Research Report on market supply and demand and strategy of China's Sodium Tetraphenylborate (cas+143-66-8) industry
Accounting regulations and professional ethics [9]
建筑建材行业经销商协同系统解决方案:赋能企业构建核心竞争力