当前位置:网站首页>[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 ;
}
边栏推荐
- Understand asp Net core - Authentication Based on jwtbearer
- Why do you say that the maximum single table of MySQL database is 20million? Based on what?
- 51 single chip microcomputer temperature alarm based on WiFi control
- World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
- The test experience "tortured" by the PMP test is worth your review
- DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
- Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
- How to decrypt worksheet protection password in Excel file
- NoSQL之readis配置与优化(终章)
- GO开发:如何利用Go单例模式保障流媒体高并发的安全性?
猜你喜欢

Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent

程序员怎么才能提高代码编写速度?

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

Position encoding practice in transformer

L1-072 scratch lottery

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

新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业

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

MFC implementation of ACM basic questions encoded by the number of characters

~89 deformation translation
随机推荐
Hash table
高度剩余法
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
Can you really use MySQL explain?
Market trend report, technical innovation and market forecast of China's hair repair therapeutic apparatus
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
China Indonesia adhesive market trend report, technological innovation and market forecast
Research Report on market supply and demand and strategy of China's plastics and polymer industry
Research Report on market supply and demand and strategy of China's well completion equipment industry
Start by counting
手里10万元存款买什么理财产品收益最高?
Spark 中的 Rebalance 操作以及与Repartition操作的区别
Transformer中position encoding实践
祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022
ECCV 2022 released: 1629 papers were selected, and the employment rate was less than 20%
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
Accounting regulations and professional ethics [6]
overflow:auto与felx结合的用法
Accounting regulations and professional ethics [9]
Opencv learning -- geometric transformation of image processing