ACWING 第 76 场周赛 ABC

https://www.acwing.com/activity/content/2589/

这场周赛也很简单,除了C我在赛场上写的时候有点小bug,赛时没改出来,哎,真废啊

4713. 反转字符串

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL INF=1e9;
const LL N=5000200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        string s,c;
        cin>>s>>c;
        bool flag=true;
        reverse(s.begin(),s.end());
        if(s==c) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

4714. 数对

手动模拟一下就可以找到规律

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL INF=1e9;
const LL N=5000200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        map<char,LL> mp;
        for(LL i=0;i<s.size();i++)
        {
            mp[s[i]]++;
        }
        LL sum=0;
        for(LL i=48;i<=57;i++)
        {
            char op=(char)i;
            //cout<<op<<" ";
            sum+=(LL)(mp[op]*mp[op]);
        }
        for(int i=97;i<=122;i++)
        {
            char op=(char)i;
            //cout<<op<<" ";
            sum+=(LL)(mp[op]*mp[op]);
        }
        cout<<sum<<endl;
        mp.clear();
    }
    return 0;
}

4715. 构造数组

题目大意:

按照字符串给出的相邻两两数字的比较,构造出这样的数组。

一定会有答案。
输入样例1:
5
><><
输出样例1:
2 1 2 1 2
输入样例2:
5
=<<<
输出样例2:
1 1 2 3 4

数据范围在2000内,直接暴力。固定往后找的同时,遇到不符合条件的直接回溯更正。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=200200,M=2002;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        string s;
        cin>>s;
        s=" "+s;
        a[0]=1;
        for(int i=1;i<=n-1;i++)
        {
            if(s[i]=='=') a[i]=a[i-1];
            else if(s[i]=='<') a[i]=a[i-1]+1;
            else if(s[i]=='>')
            {
                a[i]=1;
                if(a[i-1]==1) a[i]=0;
            }
            if(a[i]<=0)
            {
                a[i]=1;
                int j=i;
                while(j>=1)
                {
                    if(s[j]=='>'&&a[j-1]<(a[j]+1)) a[j-1]=a[j]+1;
                    else if(s[j]=='=') a[j-1]=a[j];
                    else break;
                    j--;
                }
            }
        }
        for(int i=0;i<=n-1;i++)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
        s.clear();
    }
    return 0;
}
posted @ 2022-11-07 17:19  高尔赛凡尔娟  阅读(18)  评论(0编辑  收藏  举报