AcWing 第 86 场周赛 ABC

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

4794. 健身

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=1000200,M=4002;
LL a[N],sum[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        LL sum1=0,sum2=0,sum3=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(i%3==1) sum1+=a[i];
            else if(i%3==2) sum2+=a[i];
            else sum3+=a[i];
        }
        if(sum1>sum2&&sum1>sum3) cout<<"chest"<<endl;
        else if(sum2>sum1&&sum2>sum3) cout<<"biceps"<<endl;
        else cout<<"back"<<endl;
    }
    return 0;
}

4795. 安全区域

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=1000200,M=4002;
LL a[N],sum[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;
        LL sum=n*n;
        map<LL,LL> r,c;
        LL sumr=0,sumc=0;
        for(int i=1;i<=m;i++)
        {
            LL x,y;
            cin>>x>>y;
            if(r[x]==0)
            {
                r[x]++;
                sumr++;
                sum-=(n-sumc);
            }
            if(c[y]==0)
            {
                c[y]++;
                sumc++;
                sum-=(n-sumr);
            }
            cout<<sum<<" ";
        }
    }
    return 0;
}

4796. 删除序列

先压缩数字 在进行状态机dp的计算

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=100020,M=4002;
LL a[N],sum[N],f[N][2];
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> mp;
        vector<LL> v;
        v.push_back(0);
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            mp[a[i]]++;
            if(mp[a[i]]==1) v.push_back(a[i]);
        }
        sort(v.begin(),v.end());
        //for(int i=0;i<v.size();i++)
        //    cout<<v[i]<<" ";
        //cout<<endl;
        f[0][0]=f[1][0]=0;
        LL maxn=0;
        for(int i=1;i<v.size();i++)
        {
            f[i][0]=max(f[i-1][1],f[i-1][0]);
            if(v[i-1]+1<v[i]) f[i][1]=max(f[i-1][1],f[i-1][0])+v[i]*mp[v[i]];
            else f[i][1]=f[i-1][0]+v[i]*mp[v[i]];
            maxn=max({maxn,f[i][0],f[i][1]});
        }
        cout<<maxn<<endl;
    }
    return 0;
}
posted @ 2023-01-14 21:17  Vijurria  阅读(5)  评论(0编辑  收藏  举报