栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

AcWing每日一题2014 岛

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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<

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/699236.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号