zoukankan      html  css  js  c++  java
  • 第 3 场周赛

    3660. 最短时间

    签到。

    距离目标点((r,c))最远的一定是四个顶点中的某一个点。

    int n,m;
    int r,c;
    
    int main()
    {
        int T;
        cin>>T;
        while(T--)
        {
            cin>>n>>m>>r>>c;
            cout<<max(r-1,n-r)+max(c-1,m-c)<<endl;
        }
        
        return 0;
    }
    

    3661. 重置数列

    贪心。

    观察到(1 le a_i le 100),故枚举(a_i)的所有取值,假设当前枚举的值为(c),判断使得数列中所有元素的值均为(c),最少需要进行多少次操作。

    由于最多可使得长度为(k)的区间中的元素变为某一特定值,对于某一元素值不等于(c)的位置(i),则将([i sim i+k-1])这一段的元素值全部变为(c),所需的操作次数加一。

    const int N = 1e5+10;
    int a[N];
    bool vis[110];
    int n,k;
    
    int main()
    {
        int T;
        cin>>T;
        while(T--)
        {
            cin>>n>>k;
        
            for(int i=0;i<n;i++) cin>>a[i],vis[a[i]]=true;
            
            int res=n;
            for(int i=1;i<=100;i++)
                if(vis[i])
                {
                    int cnt=0;
                    for(int j=0;j<n;)
                        if(a[j] != i)
                            j+=k,cnt++;
                        else
                            j++;
                    res=min(res,cnt);
                }
            
            cout<<res<<endl;
        }
        
        return 0;
    }
    

    3662. 最大上升子序列和

    状态表示:

    (f(i))表示考虑前(i)个元素,且选第(i)个数的情况下, 最长上升子序列和的最大值。

    状态转移:

    [f(i)=max_{a_j < a_i}f(j)+a_i ]

    考虑以(a_i)为下标,(f_i)为元素值,建立树状数组,则每次查询([1,a_i-1])的前缀最大值,同时将(a_i)位置上的值修改为(f_i)。由于(a_i)的范围过大((10^9)),可对(a)数组离散化,以离散化后的值作为树状数组的下标。

    边界:

    [f(0)=0 ]

    const int N = 1e5+10;
    int a[N],b[N];
    LL c[N];
    LL f[N];
    int n,len;
    
    int lowbit(int x)
    {
        return x&-x;
    }
    
    void add(int x,LL v)
    {
        for(int i=x;i<=len;i+=lowbit(i))
            c[i]=max(c[i],v);
    }
    
    LL query(int x)
    {
        LL res=0;
        for(int i = x; i; i -= lowbit(i))
            res=max(res,c[i]);
        return res;
    }
    
    void discrete()
    {
        sort(b+1,b+n+1);
        len=unique(b+1,b+n+1)-b-1;
    }
    
    int get(int x)
    {
        return lower_bound(b+1,b+len+1,x)-b;
    }
    
    int main()
    {
        cin>>n;
        
        for(int i=1;i<=n;i++) cin>>a[i],b[i]=a[i];
        
        discrete();
        
        LL res=0;
        for(int i=1;i<=n;i++)
        {
            int k=get(a[i]);
            f[i]=query(k-1)+a[i];
            res=max(res,f[i]);
            add(k,f[i]);
        }
        
        cout<<res<<endl;
        
        return 0;
    }
    
  • 相关阅读:
    Java8新特性之Lambda
    SSL证书自签名使用及监控
    Java读源码之LockSupport
    Java读源码之ThreadLocal
    Java读源码之Thread
    Java读源码之Object
    Python 命令行参数解析工具 argparse
    Python调用 Openstack 主要服务(keystone,nova,glance,neutron,heat)
    我对计算机系统的理解
    wireshark长时间抓包分多个文件
  • 原文地址:https://www.cnblogs.com/fxh0707/p/14880334.html
Copyright © 2011-2022 走看看