zoukankan      html  css  js  c++  java
  • Codeforces 1272D Remove One Element

    思路:

    将每一段连续的上升序列看成一个整体,然后挨个判断每两个相邻的整体是否可以合并;

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef pair<int,int> P;
    typedef long long LL;
    #define fi first
    #define sc second
    #define pb(a) push_back(a)
    #define mp(a,b) make_pair(a,b)
    #define pt(a) cerr<<a<<"---
    "
    #define rp(i,n) for(int i=0;i<n;i++)
    #define rpn(i,n) for(int i=1;i<=n;i++)
    const int maxn=2e5+99;
    int arr[maxn];
    vector<P> v;
    int main(){
    	ios::sync_with_stdio(false);
    	cin.tie(nullptr);
    	int n; cin>>n;
    	rpn(i,n) cin>>arr[i];
    	int p=1,q=2;
    	while(q<=n){
    		if(arr[q]>arr[q-1]) q++;
    		else{
    			v.pb(mp(p,q-1));
    			p=q++;
    		}
    	}
    	if(p!=n) v.pb(mp(p,n));
    	int res=1; 
    	for(P p:v) res=max(res,p.sc-p.fi+1);
    	for(int i=1;i<v.size();i++){
    		int a=v[i-1].fi,b=v[i-1].sc;
    		int c=v[i].fi,d=v[i].sc;
    		if(b-a>=1&d-c>=1){
    			if(arr[b]<arr[c+1]||arr[b-1]<arr[c]) res=max(res,d-a);
    		}
    	}
    	cout<<res;
    	return 0;
    } 
    
  • 相关阅读:
    Vue常见问题总结
    vue学习记录
    内卷
    at least once 和 at most once 问题
    IO学习笔记(全)
    IO学习笔记7
    IO学习笔记6
    IO学习笔记5
    IO学习笔记4
    IO学习笔记3
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308751.html
Copyright © 2011-2022 走看看