A.Equivalent Prefixes

本文深入探讨了等价数组的概念,即所有子区间满足最小值下标相等的最大数组长度问题。通过分析如何判断下标是否满足条件,以及在枚举过程中如何优化循环,提供了详细的算法思路和C++实现代码。

题目大意:等价数组定义为(1≤l≤r≤m)中,所有的子区间都满足最小值下标相等,找出最大的m。

思路:我们枚举下标,如果当前下标i不满足,显然我们就可以结束循环了。那么现在的关键是怎么样去判断下标i是否满足。

①首先我们需要知道每增加一个数,那么多了哪些区间。在枚举的过程中,我们会发现如果对于AB新增一个数C,那么增加的区间则是BC,ABC。显然增加的区间是从当前下标i一直到下标1。这个时候我们知道第二层循环应该就是从i-1一直到1。

②然后我们需要判断当前增加的区间是否满足。

    1.区间j到i,最小值下标改变。只有当A,B数组同时改变才满足,其他情况不满足。

    2.区间j到i,最小值下标不改变。当前i是满足答案的,我们可以直接结束循环,i++。(解释一下为什么,假设A数组为{a1,b1},B数组为{a2,b2},且j=2,现在A数组新增的数为c1,B数组增加的数为C2,

        那么由于最小值不改变,因此c1>b1,c2>b2。如果能枚举到这一步,那么i=2是满足条件的,则此时只有两种情况①b1>a1&&b2>a2②b1<a1&&b2<a2,而无论哪一种情况,都不会改变最小值下标)

#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1e5+10;
int a[maxn],b[maxn];
int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    int n;
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<=n;i++)
            cin>>b[i];
        int ans=n;
        for(int i=1;i<=n;i++)
        {
            bool flag=true;
            for(int j=i-1;j;j--)
            {
                if((a[j]<a[i]&&b[j]>b[i])||(a[j]>a[i]&&b[j]<b[i]))
                {
                    flag=false;
                    //coutl<<i<<" "<<a[i]<<" "<<a[j]<<" "<<b[i]<<" "<<b[j]<<endl;
                    break;
                }
                else if(a[j]<a[i]&&b[j]<b[i])break;
            }
            if(!flag)
            {
                ans=i-1;
                break;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/pbzyl999/p/11209553.html

[root@master ~]# kubeadm config migrate --help This command lets you convert configuration objects of older versions to the latest supported version, locally in the CLI tool without ever touching anything in the cluster. In this version of kubeadm, the following API versions are supported: - kubeadm.k8s.io/v1beta3 Further, kubeadm can only write out config of version "kubeadm.k8s.io/v1beta3", but read both types. So regardless of what version you pass to the --old-config parameter here, the API object will be read, deserialized, defaulted, converted, validated, and re-serialized when written to stdout or --new-config if specified. In other words, the output of this command is what kubeadm actually would read internally if you submitted this file to "kubeadm init" Usage: kubeadm config migrate [flags] Flags: --allow-experimental-api Allow migration to experimental, unreleased APIs. -h, --help help for migrate --new-config string Path to the resulting equivalent kubeadm config file using the new API version. Optional, if not specified output will be sent to STDOUT. --old-config string Path to the kubeadm config file that is using an old API version and should be converted. This flag is mandatory. Global Flags: --add-dir-header If true, adds the file directory to the header of the log messages --kubeconfig string The kubeconfig file to use when talking to the cluster. If the flag is not set, a set of standard locations can be searched for an existing kubeconfig file. (default "/etc/kubernetes/admin.conf") --log-file string If non-empty, use this log file (no effect when -logtostderr=true) --log-file-max-size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800) --one-output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true) --rootfs string [EXPERIMENTAL] The path to the 'real' host root filesystem. --skip-headers If true, avoid header prefixes in the log messages --skip-log-headers If true, avoid headers when opening log files (no effect when -logtostderr=true) -v, --v Level number for the log level verbosity
09-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值