AcWing每日一题2014 岛

AcWing每日一题2014 岛,第1张

AcWing每日一题2014 岛

题目链接https://www.acwing.com/problem/content/description/2016/

思路:先找递增序列,然后算序列最大重叠

代码:

#include
using namespace std;
const int maxn=100005;
int a[maxn];
struct b{
    int di;
    int hi;
} po[maxn]; 
struct c{
    int w;
    int flag;
} po2[maxn*2];
bool cmp(c x,c y){
    return x.w }
int main(){
    int n;cin>>n;
    int di=0,hi=0,j=0,k=0,sum=0,ma=0;
    for(int i=0;i<=n;i++){
        if(i!=n)cin>>a[i];
        else{
            a[i]=0;
        }
        if(a[i]>hi){
            hi=a[i];
        }
        else if(a[i]             if(di!=hi){
                po[j].di=di;
                po[j++].hi=hi;
                    
            }
            hi=a[i];
            di=a[i];
                 
        } 
    } 
    for(int i=0;i         po2[k].w=po[i].di;
        po2[k++].flag=0;
        po2[k].w=po[i].hi;
        po2[k++].flag=1;        
    }
    sort(po2,po2+k,cmp);
    for(int i=0;i         if(po2[i].flag==0){
            sum++;
            ma=sum>ma?sum:ma;
        } 
        if(po2[i].flag==1){
            sum--;
        }
    }
    cout<

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5699362.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存