Codeforces Round 866 (Div. 2) ABC

https://codeforces.com/contest/1820

A. Yura's New Name

题目大意:

给定一个字符串,每次这个表情^^或者这个表情^_^就是合法的

问我们这个字符串至少要添加多少东西使得怎么看都是合法的?
input 
7
^______^
___^_^^^_^___^
^_
^
^_^^^^^_^_^^
___^^
_
output 
5
5
1
1
0
3
2
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e7+10,M=4023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL sum=0;
        string s;
        cin>>s;
        if(s=="^") cout<<"1"<<endl;
        else
        {
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='^') ;
            else if(s[i]=='_')
            {
                if(i==0||s[i-1]=='_') sum++;
                if(i==s.size()-1||s[i+1]=='_') sum++;
                s[i]='^';
            }
            //cout<<sum<<endl;
        }
        cout<<sum<<endl;
        }
    }
    return 0;
}

B. JoJo's Incredible Adventures

题目大意:

给定一个字符串,这个字符串每次可以从后面拉一个字符到前面形成一个新的字符串

这样每次组成的字符串就成了一个矩阵

问这个矩阵里面可以组成的最矩形面积是多少?
input 
5
0
1
101
011110
101010
output 
0
1
2
6
1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e7+10,M=4023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        LL one=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='1') one++;
        }
        if(one==s.size()) cout<<s.size()*s.size()<<endl;
        else
        {
            LL maxn=0,sum=0;
            for(int i=0;i<s.size();i++)
            {
                if(s[i]=='0') sum=0;
                else sum++;
                maxn=max(maxn,sum);
            }
            sum=0;
            for(int i=0;i<s.size();i++)
            {
                if(s[i]=='0') break;
                else sum++;
            }
            for(int i=s.size()-1;i>=0;i--)
            {
                if(s[i]=='0') break;
                else sum++;
            }
            maxn=max(maxn,sum);
            if(maxn%2==1) cout<<(maxn/2+1)*(maxn/2+1)<<endl;
            else cout<<(maxn/2)*(maxn/2+1)<<endl;
        }
    }
    return 0;
}

C. Constructive Problem

题目大意:

给定一组数据,问我们能不能改一排数据,使得刚好mex+1。
input 
4
3
1 2 1
4
0 2 2 0
4
3 2 0 2
1
0
output 
Yes
Yes
No
No

思路:如果每个数都连续且只有一个,那么必定不可能;
如果每个数连续且任意一个不只一个,就可以把这个数字改成更大的数,从而把mex变大一个;
如果当前数组中的mex+1存在,那么必须把这一排都改了,不然要么出现越来越大的mex,要么出现不变的mex,从而判断一下,满足条件(这一排之间不能出现小数被删没了的情况)即可;
如果mex+1不存在,但是比mex+1还大的数字存在,直接随便改,一个也行,几个都行。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e7+10,M=4023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL a[200010];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        map<LL,LL> num;
        map<LL,PII> mp;
        LL b[200010],cnt=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            num[a[i]]++;
            if(num[a[i]]==1)
            {
                b[++cnt]=a[i];
                mp[a[i]].first=i;
            }
            mp[a[i]].second=i;
        }
        LL mex=0;
        sort(b+1,b+1+cnt);
        //for(int i=1;i<=cnt;i++) cout<<b[i]<<" "; cout<<endl;
        LL idx=-1;
        for(int i=1;i<=cnt;i++)
        {
            if(b[i]==mex) mex++;
            else
            {
                idx=i;
                break;
            }
        }
        LL ans=0;
        if(idx==-1)//说明已经是顺序排列的情况
        {
            bool flag2=false;
            for(int i=1;i<=cnt;i++)
            {
                if(num[b[i]]>1)
                {
                    flag2=true;
                    break;
                }
            }
            if(flag2==false) cout<<"No"<<endl;//直接瞄准有无多余数字可供修改
            else cout<<"Yes"<<endl;
        }
        else if(idx!=-1)
        {
            ans=b[idx];
            //cout<<mex<<" "<<idx<<" "<<ans<<endl;
            if(ans-mex>=2) cout<<"Yes"<<endl;
            else
            {
                bool flag=true;
                for(int i=mp[ans].first;i<=mp[ans].second;i++)
                {
                if(a[i]<ans)
                {
                    num[a[i]]--;
                    if(num[a[i]]<=0)
                    {
                        flag=false;
                        break;
                    }
                }
                }
                if(flag==true) cout<<"Yes"<<endl;
                else cout<<"No"<<endl;
            }
        }
    }
    return 0;
}
posted @ 2023-04-17 20:46  高尔赛凡尔娟  阅读(64)  评论(0编辑  收藏  举报