首页 > 其他分享 >Acwing 第82场周赛ABC

Acwing 第82场周赛ABC

时间:2022-12-18 09:45:27浏览次数:49  
标签:周赛 typedef ABC const int LL 样例 cin 82

https://www.acwing.com/activity/content/competition/problem_list/2696/
C我前几个月碰到了原题hh,原题在cf上
4782. 第k个数

题目大意:
输出从大到小的第k个数字
输入样例1:
5 3
20 10 30 40 10
输出样例1:
20
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=200200,M=2002;
const LL INF=1e9;
const LL MAXN=1e18;
LL a[N],b[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        sort(a+1,a+1+n);
        reverse(a+1,a+1+n);
        cout<<a[m]<<endl;
    }
    return 0;
}

4783. 多米诺骨牌

题目大意:

求左右倒下之后依然竖立着的数量。
输入样例1:
14
.L.R...LR..L..
输出样例1:
4

竖立的就只有两种情况:不受影响的和两边分别是RL并且为奇数的时候,中间会剩下一个竖立的

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=200200,M=2002;
const LL INF=1e9;
const LL MAXN=1e18;
LL a[N],b[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;
        int sum=0;
        int last=-1;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='L')
            {
                if(last==-1) ;
                else
                {
                    if(s[last]=='L') ;
                    else
                    {
                        if((i-last)%2==0) sum++;
                    }
                }
                last=i;
            }
            else if(s[i]=='R')
            {
                if(last==-1) sum+=i;
                else
                {
                    if(s[last]=='R') ;
                    else
                    {
                        sum+=(i-last)-1;
                    }
                }
                last=i;
            }
        }
        if(last!=s.size()-1&&(s[last]=='L'||last==-1))
        {
            sum+=s.size()-1-last;
        }
        cout<<sum<<endl;
    }
    return 0;
}

4784. 构造序列

题目大意:

请你构造一个 01 序列,序列需要满足以下所有要求:

恰好包含 n 个 0 和 m 个 1。
不存在两个或两个以上的 0 连续相邻。
不存在三个或三个以上的 1 连续相邻。
输入样例1:
1 2
输出样例1:
101
输入样例2:
4 8
输出样例2:
110110110101
输入样例3:
4 10
输出样例3:
11011011011011
输入样例4:
1 5
输出样例4:
-1

思考好了特判条件,放置条件就直接秒
这题cf上才1300,还是1400我忘记了,不难

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=200200,M=2002;
const LL INF=1e9;
const LL MAXN=1e18;
LL a[N],b[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        string s;
        if((n-1)<=m&&m<=n*2+2)
        {
            if(m==n-1)
            {
                for(int i=1;i<n;i++)
                {
                    s+="01";
                }
                s+="0";
            }
            else if(m==n)
            {
                for(int i=1;i<=n;i++)
                {
                    s+="01";
                }
            }
            else
            {
                LL rest=m-(n+1);
                s="1";
                if(rest>0)
                {
                    s+="1";
                    rest--;
                }
                for(int i=1;i<=n;i++)
                {
                    s+="01";
                    if(rest>0)
                    {
                        s+="1";
                        rest--;
                    }
                }
            }
            cout<<s<<endl;
        }
        else cout<<"-1"<<endl;
    }
    return 0;
}

标签:周赛,typedef,ABC,const,int,LL,样例,cin,82
From: https://www.cnblogs.com/Vivian-0918/p/16989979.html

相关文章