当前位置:网站首页>[Acwing] 58周赛 4489. 最长子序列
[Acwing] 58周赛 4489. 最长子序列
2022-07-04 15:05:00 【*DDL_GzmBlog】
前言
t a g : tag : tag:思维
传送门 :
题意 :
给定一个 上升 的数组,求一个子序列使得子序列中的元素满足 a j ∗ 2 ≥ a j + 1 a_j*2\ge a_{j+1} aj∗2≥aj+1,询问合法子序列的最大长度
思路 :
因为给出的数组是 上升的
因此如果 a 1 ∗ 2 ≥ a 3 a_1*2\ge a_3 a1∗2≥a3存在,那么必然存在 a 1 ∗ 2 ≥ a 2 a_1 *2\ge a_2 a1∗2≥a2
则这个条件使得所求答案 连续, 因此我们只需要 O n On On的扫一遍即可
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 ;
}
边栏推荐
- Sequence diagram data modeling and industrial chain analysis
- Embedded software architecture design - function call
- Research Report on market supply and demand and strategy of China's Sodium Tetraphenylborate (cas+143-66-8) industry
- China tall oil fatty acid market trend report, technical dynamic innovation and market forecast
- 世界环境日 | 周大福用心服务推动减碳环保
- C implementation defines a set of intermediate SQL statements that can be executed across libraries
- c# 实现定义一套中间SQL可以跨库执行的SQL语句
- Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
- Market trend report, technical innovation and market forecast of electrochromic glass and devices in China and Indonesia
- Opencv learning -- geometric transformation of image processing
猜你喜欢
Visual Studio 2019 (LocalDB)MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782
"Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
How to decrypt worksheet protection password in Excel file
Why do you say that the maximum single table of MySQL database is 20million? Based on what?
Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782
Model fusion -- stacking principle and Implementation
overflow:auto与felx结合的用法
Transformer中position encoding实践
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)
随机推荐
Model fusion -- stacking principle and Implementation
Inside and outside: flow chart drawing elementary: six common mistakes
Research Report on plastic recycling machine industry - market status analysis and development prospect forecast
智慧物流园区供应链管理系统解决方案:数智化供应链赋能物流运输行业供应链新模式
Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
Use and principle of thread pool
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
Cut! 39 year old Ali P9, saved 150million
跳跃表实例
Research Report on market supply and demand and strategy of tetramethylpyrazine industry in China
Vscode prompt Please install clang or check configuration 'clang executable‘
China tall oil fatty acid market trend report, technical dynamic innovation and market forecast
C implementation defines a set of intermediate SQL statements that can be executed across libraries
Array filter fliter in JS
一图看懂ThreadLocal
Final consistency of MESI cache in CPU -- why does CPU need cache
安信证券排名 网上开户安全吗
昆明三环闭合工程将经过这些地方,有在你家附近的吗?
Go language loop statement (under Lesson 10)
MFC implementation of ACM basic questions encoded by the number of characters