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

Acwing 第 83 场周赛 ABC

时间:2022-12-24 21:46:09浏览次数:66  
标签:周赛 typedef ABC const int LL 样例 cin 83

https://www.acwing.com/activity/content/competition/problem_list/2714/

4785. 奇偶

题目大意:

给定一个字符串,问我们去重后单词数是奇是偶?
输入样例1:
wjmzbmr
输出样例1:
even
输入样例2:
xiaodao
输出样例2:
odd
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=2002;
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;
        map<char,LL> mp;
        LL sum=0;
        for(int i=0;i<s.size();i++)
        {
            mp[s[i]]++;
            if(mp[s[i]]==1) sum++;
        }
        if(sum%2==0) cout<<"even"<<endl;
        else cout<<"odd"<<endl;
    }
    return 0;
}

4786. 闯关

题目大意:

给定n个关卡,每个关卡后通过可获得ai的分数,m个关卡的分数可以任我们改变,但是不能低于原ai,也不能超过我们已获得的总分
输入样例1:
4 1
1 3 7 5
3
输出样例1:
18

贪一把

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=2002;
struct node
{
    LL x;
    LL flag=0;
}a[N];
bool cmp(node l,node r)
{
    if(l.flag!=r.flag) return l.flag<r.flag;
    else return l.x>r.x;
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        map<LL,LL> mp;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i].x;
        }
        for(int i=1;i<=m;i++)
        {
            LL x;
            cin>>x;
            a[x].flag=1;
        }
        sort(a+1,a+1+n,cmp);
        //for(int i=1;i<=n;i++)
        //{
        //    cout<<a[i].x<<" "<<a[i].flag<<endl;
        //}
        LL sum=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i].flag==0) sum+=a[i].x;
            else sum+=max(a[i].x,sum);
        }
        cout<<sum<<endl;
    }
    return 0;
}

4787. 构造序列

题目大意:

让我们构造一个长度为n,价值为m的序列:

对于一个长度为 n 的正整数序列 a1,a2,…,an,我们这样规定该序列的价值:

如果 n 为偶数,则序列价值为 gcd(a1,a2)+gcd(a3,a4)+…+gcd(an−1,an)。
如果 n 为奇数,则序列价值为 gcd(a1,a2)+gcd(a3,a4)+…+gcd(an−2,an−1)。

构造不出来输出-1,可以的话输出构造出来的序列。
输入样例1:
5 2
输出样例1:
1 2 3 4 5

注意范围是突破口:1≤ai≤10^9。 1≤n≤10^5, 0≤m≤10^8。

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

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

相关文章

  • leetcode笔记——324周赛
    第三题中设置字典:G = defaultdict(set)这样默认每个item是个set,可以直接用G[i].add(),不用G.get()再判断了第三题中有个判断:return any(i != x and i!=y and......
  • abc--275--C
    C-CountingSquares//会重复,所以要除4#include<bits/stdc++.h>usingnamespacestd;chars[10][10];boolcheck(intx,inty){returnx>=1&&y>=1&&x<=9&&y<......
  • POJ 1837 Balance
    POJ1837Balance题意:一个天平上有\(C(2<=C<=20)\)个挂钩,挂钩所在位置在区间\([-15,15]\)。你的手里有\(G(2<=G<=20)\)个砝码,每个砝码的重量在区间\([1,25]\)。......
  • luoguP5383 普通多项式转下降幂多项式 题解
    学习了bztMinamoto大佬的做法,希望这篇题解可以使得那个方法更加易于理解。既然下降幂多项式转普通多项式可以采取分治\(\operatorname{NTT}\),那么可以猜测逆过来也可以......
  • [ABC264F] Monochromatic Path
    ProblemStatementWehaveagridwith$H$rowsand$W$columns.Eachsquareispaintedeitherwhiteorblack.Foreachintegerpair$(i,j)$suchthat$1\leq......
  • [ABC264Ex] Perfect Binary Tree
    ProblemStatementWehavearootedtreewith$N$verticesnumbered$1,2,\dots,N$.ThetreeisrootedatVertex$1$,andtheparentofVertex$i\ge2$isVerte......
  • [ABC264G] String Fair
    ProblemStatementInastringfair,theydeterminethebeautyofanon-emptystring$S$consistingoflowercaseEnglishletters.Thebeautyofstring$S$equal......
  • Codeforces Round #836 (Div. 2)构造场
    今天的CF居然是这样的全是构造题,顺便把牛客上的一道构造写了C题待补链接......
  • [ABC267G] Increasing K Times
    ProblemStatementYouaregivenanintegersequence$A=(A_1,\dots,A_N)$oflength$N$.Findthenumber,modulo$998244353$,ofpermutations$P=(P_1,\dot......
  • [ABC267F] Exactly K Steps
    ProblemStatementYouaregivenatreewith$N$vertices.Theverticesarenumbered$1,\dots,N$,andthe$i$-th($1\leqi\leqN-1$)edgeconnectsVertice......