Acwing 第 83 场周赛 ABC

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;
}
posted @ 2022-12-24 21:33  高尔赛凡尔娟  阅读(9)  评论(0编辑  收藏  举报