Codeforces Round #616 (Div. 2)【A - D】

题目来源:https://codeforces.com/contest/1291
这把太惊险了,差点掉分了,不过还是反映了很多问题。
在这里插入图片描述
首先就是这张图,我昨天人都傻了,怎么WA了这么多。菜是原罪…


1291A - Even But Not Even

这题我上来题目都看错了,直接WA两发。我以为是 位数为偶数 且 值为奇数
实际上是 每位数的和为偶数且值为奇数
也没要求大小,仔细想想。值为奇数就说明个位一定是奇数,如果每位数的和为偶数,那一定除了个位还有一位奇数。那我们只要找到两个奇数组成一个两位数就ok了。然后我没看到 顺序不能变 又WA了

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
char s[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    int t;
    r(t);
    while(t--){
        r(n);
        scanf("%s",s+1);
        if(n<=1){
            cout<<-1<<endl;
            continue;
        }
        int first=-1,last=-1;
        FOR(i,1,n){
            if(first==-1&&((s[i]-'0')&1)) first=s[i]-'0';
            else if(last==-1&&((s[i]-'0')&1)) last=s[i]-'0';
        }
        if(last!=-1&&first!=-1){
            cout<<first*10+last<<endl;
        }
        else cout<<-1<<endl;
    }
    return 0;
}


1291B - Array Sharpening

这题我是真的傻了,没考虑到细节问题…
锋利的数组就是 严格单调递减、严格单调递增或先严格递增再严格递减
那其实我们找到最小的某种情况的序列,然后和原序列比较就好了。
如果单调递增 我们用 0 1 2 3 4 5 … n去比
如果单调递减 我们用 n … 5 4 3 2 1 去比
如果先增再减 我们先用0 1 2 3 4 5 …n … 3 2 1 0去比
如果做法统一 我们其实把单调递减的情况 也可以变成先增再减的判断(因为你可以把左边最大的减很多次 减得比最右边还小)
那总的判断就是先用 0 1 2 3 4 … i 去比 如果原数比i小 那后面应该是单调递减了
注意递减反过来看也要从0开始这样才能保证你的最小 0 1 2 3 4 …i k k-1 …0
这个i前面不一定是i-1,i可以是f[i-1] 【hack 数据为 1 2 3 2 1 0】

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
int f[N];
int g[N];
template<class T>
inline void read(T &x)
{
    char c;
    x=1;
    while((c=getchar())<'0'||c>'9')
        if(c=='-')
            x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9')
        res=res*10+c-'0';
    x*=res;
}
int main()
{
    int t;
    r(t);
    while(t--){
        r(n);
        FOR(i,1,n) r(f[i]);
        int maxx,now=0;
        FOR(i,1,n){
            if(f[i]>=now){
                maxx=f[i];
                now++;
            }
            else{
                g[i-1]=maxx;
                break;
            }
        }
        FOR(i,1,now) g[i]=i-1;
        bool flag=1;
        for(int i=n;i>now;i--){
            g[i]=n-i;
            if(g[i]>=maxx){
                flag=0;
            }
        }
        FOR(i,1,n){
            if(f[i]<g[i]) flag=0;
        }
        if(flag) cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}



1290A - Mind Control

这题简单 早知道先写这题了…
首先暴力肯定可以过,复杂度O(n2)
但是我看了题解之后发现其实可以用单调deque优化为线性的复杂度

听话的人肯定尽量让自己最大,不听话的人肯定尽量让自己最小,假设听话的有x个,不听话的有y个,我们只需要考虑自己前面的人,故令x+y=m-1
如果g[ i ]=max(f[ i+1 ],g[ i+1+n-m ]) 那其实每次都是在一个m-1的长度的序列里面从左往右滑动长度为y的窗口 每次将窗口的最小值取max

暴力:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
int n,m;
int f[N];
template<class T>
inline void read(T &x)
{
    char c;
    x=1;
    while((c=getchar())<'0'||c>'9')
        if(c=='-')
            x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9')
        res=res*10+c-'0';
    x*=res;
}
int main()
{
    int t;
    r(t);
    while(t--)
    {
        int k;
        rrr(n,m,k);
        FOR(i,1,n){
            r(f[i]);
        }
        int x=min(m-1,k);
        int y=max(0,m-1-x);
        int ans=0;
        FOR(i,0,x){
            int res=INF;
            FOR(j,0,y){
                int l=i+j;
                int r=m-1-l;
                res=min(res,max(f[l+1],f[n-r]));
            }
            if(res!=INF) ans=max(res,ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}

单调deque
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
int n,m;
int f[N];
int g[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    int t;
    r(t);
    while(t--){
        int k;
        rrr(n,m,k);
        int x=min(m-1,k);
        int y=max(0,m-1-x);
        FOR(i,1,n){
            r(f[i]);
        }
        FOR(i,0,m-1){
            g[i]=max(f[i+1],f[i+1+n-m]);
        }
        deque<int> q;
        int j=0;
        int ans=0;
        FOR(i,0,x){
            while(q.size()&&q.front()<i){
                q.pop_front();
            }
            for(;j<=i+y;j++){
                while(q.size()&&g[q.back()]>=g[j]){
                    q.pop_back();
                }
                q.push_back(j);
            }
            ans=max(ans,g[q.front()]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


1290B - Irreducible Anagrams

我看到这题的时候还有30分钟,看了15分钟没看懂…我fo了。一看好友只过了一个,然后时间也不早了,就去开始夜生活了…早上一起来,他们怎么都过了…
首先只有1个元素肯定是YES,其次虽然题目说可以划分为很多段,但是我们的目的只是找到一段,所以我们不妨默认为只能划分为2段(这样可变性最高)
如果是a…b 我们一定能找到 一个 b…a 所以收尾不相等肯定YES
如果是a…a 假如是a…x…y…a 一定能找到 x…y 故有三个不同元素存在肯定YES

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=2e5+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
int n,m;
char str[N];
int f[N][26];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    scanf("%s",str+1);
    r(n);
    int len=strlen(str+1);
    FOR(i,1,len){
        FOR(j,0,25){
            if(str[i]-'a'==j) f[i][j]=f[i-1][j]+1;
            else f[i][j]=f[i-1][j];
            //cout<<f[i][j]<<' ';
        }
        //cout<<endl;
    }
    while(n--){
        int l,r;
        r(l); r(r);
        int cnt=0;
        FOR(i,0,25){
            if(f[r][i]-f[l-1][i]>0) cnt++;
        }
        if((cnt>=3)||(l==r)||(str[l]!=str[r])) cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}


什么时候才能再上蓝…

发布了71 篇原创文章 · 获赞 89 · 访问量 8531

猜你喜欢

转载自blog.csdn.net/weixin_43890662/article/details/104156086