当前位置:网站首页>[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 ;
}
边栏推荐
- 时序图数据建模与产业链分析
- 力扣今日题-1200. 最小绝对差
- D3D11_ Chili_ Tutorial (2): draw a triangle
- 实战:fabric 用户证书吊销操作流程
- How can programmers improve the speed of code writing?
- 基于check-point实现图数据构建任务
- I let the database lock the table! Almost fired!
- C implementation defines a set of intermediate SQL statements that can be executed across libraries
- Transformer中position encoding实践
- 对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平
猜你喜欢
What is torch NN?
~89 deformation translation
Filtered off site request to
TypeError: list indices must be integers or slices, not str
~88 running people practice
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
世界环境日 | 周大福用心服务推动减碳环保
I let the database lock the table! Almost fired!
随机推荐
Maximum subarray and matrix multiplication
同构图与异构图CYPHER-TASK设计与TASK锁机制
Research Report on market supply and demand and strategy of China's plastics and polymer industry
祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022
智慧物流園區供應鏈管理系統解决方案:數智化供應鏈賦能物流運輸行業供應鏈新模式
TypeError: not enough arguments for format string
中位数与次序统计量
Communication mode based on stm32f1 single chip microcomputer
Integration of ongdb graph database and spark
Principle and general steps of SQL injection
C language: implementation of daffodil number function
China tall oil fatty acid market trend report, technical dynamic innovation and market forecast
Anta is actually a technology company? These operations fool netizens
Go language loop statement (under Lesson 10)
C # realizes FFT forward and inverse transformation and frequency domain filtering
Go语言循环语句(第10课下)
安信证券网上开户安全吗 开户收费吗
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
Research Report on market supply and demand and strategy of surgical stapler industry in China