zoukankan      html  css  js  c++  java
  • 模拟题

    对于模拟题 一定要考虑全面 观察细节,不然代码复杂 很难编写, 想好了 看好了细节 抓住题目的

     特点 就可以减少代码量 提高准确率 一定要把细节想清楚在写。看看怎么编写 代码量最少,但想的时间不能过长 1 0分钟吧

      题目:

    话说世界上有很多超级英雄:蝙蝠侠,蜘蛛侠,超人,名字都写不出来的人等等。在他们之中有一个叫Kickass。今天他想模仿蜘蛛侠,所以他选择了一排高楼来跳。
    
    具体来说,他选择了一列N幢高楼,从左到右标号为1到N。一开始他在第K幢高楼。不幸的是,Kickass能力非常有限,只能跳到向左或向右相邻的高楼,而且他要跳到的楼的高度必须不能大于他现在处在的楼的高度。Kickass不想自己看起来很渣渣,所以他在一些高楼顶部放了蹦床,从这些高楼起跳,能跳到任何其他的高楼,不管要跳到的高楼在哪里或是多高。
    
    你的任务是找到Kickass在第K高楼起跳能跳到的最多不同的高楼数。如果Kickass跳到一幢高楼超过一次,我们只会算一次。并且,即使Kickass没有重新跳到,第K幢高楼还是要算入答案。
    View Code

    代码:

    #include<cstdio>
    #include<algorithm>
    #define N 300010
    using namespace std;
    int n,K,a[N],b[N],le,ri,tot=0,j,ma=0,maxx=0;
    int bz[N],ans=0,s=0,s1=0,s2=0;
    bool check[N];
    char c;
    
    inline int read()
    {
        int x=0,f=0; char c=getchar();
        while (c<'0' || c>'9') f=(c=='-') ? 1:f,c=getchar();
        while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        return f ? -x:x;
    }
    
    int gsum(int l,int r)
    {
        int s=0;
        for (int i=l;i<=r;i++) s+=(!bz[i]);
        return s;
    }
    
    int gans(int l,int r)
    {
        int s=0;
        for (int i=l;i<=r;i++) s+=(bz[i]);
        return s;
    }
    
    void color(int l,int r) {for (int i=l;i<=r;i++) bz[i]=1;}
    
    int last()
    {
        int zuo=0,s=0;
        for (int i=1;i<=n;i++)
        {
            if (bz[i])
            {
                if (zuo) s=max(s,i-zuo),zuo=0;
                continue;
            }
            if (!zuo) zuo=i;
            else if (a[i]<a[i-1])
            {
                s=max(s,i-zuo),zuo=i;
                continue;
            }
            s=max(s,i-zuo+1);
        }
        for (int i=1;i<=n;i++)
        {
            if (bz[i])
            {
                if (zuo) s=max(s,i-zuo),zuo=0;
                continue;
            }
            if (!zuo) zuo=i;
            else if (a[i]>a[i-1])
            {
                s=max(s,i-zuo),zuo=i;
                continue;
            }
            s=max(s,i-zuo+1);
        }
        return s;
    }
    
    int main()
    {
        n=read(),K=read();bz[K]=1;
        for (int i=1;i<=n;i++) a[i]=read();
        scanf("
    ");
        for (int i=1;i<=n;i++)
            if ((c=getchar())=='T')
            {
                bz[i]=check[i]=1;
                j=i; while (a[j]<=a[j-1] && j>1) j--,bz[j]=1;
                j=i; while (a[j]<=a[j+1] && j<n) j++,bz[j]=1;
            }
        ri=K; while (a[ri]==a[ri+1] && ri<n) ri++,bz[ri]=1,s+=check[ri];
        le=K; while (a[le]==a[le-1] && le>1) le--,bz[le]=1,s+=check[le];
        j=le; while (a[j]>=a[j-1] && j>1) j--,s1=check[j] ? j:s1;
        maxx=ri-j+1;
        j=ri; while (a[j]>=a[j+1] && j<n) j++,s2=check[j] ? j:s2;
        maxx=max(maxx,j-le+1);
        if (s1 || s2 || s) printf("%d
    ",gans(1,n)+last());
        else printf("%d
    ",maxx);
        return 0;
    }
    View Code

     1

  • 相关阅读:
    [HNOI2002]营业额统计
    HDU 1374
    HDU 3345
    HDU 2089
    Graham扫描法
    Codeforces 1144D Deduction Queries 并查集
    Codeforces 916E Jamie and Tree 线段树
    Codeforces 1167F Scalar Queries 树状数组
    Codeforces 1167E Range Deleting
    Codeforces 749E Inversions After Shuffle 树状数组 + 数学期望
  • 原文地址:https://www.cnblogs.com/Lamboofhome/p/11821903.html
Copyright © 2011-2022 走看看