Educational Codeforces Round 94 (Rated for Div. 2)

这次做了ABCD,今天下午就要上学去了溜了溜了,早上起来补的题解。

A - String Similarity

分析可知可构造w[i]=s[2*i]即可满足题意

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    IO;
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        string w;
        for(int i=0;i<n;i++) w+=s[2*i];
        cout<<w<<endl;
    }
    return 0;
}

B - RPG Protagonist

枚举+贪心
这题很有意思,昨天做的时候群友许多都说C比B简单,不过我B是1A,而Cwa2次
刚开始想了很久确实没啥思路,但是一看数据范围 2 ⋅ 1 0 5 2·10^5 2105好像直接可以枚举数量。对于题目不妨设 s ≥ w s \ge w sw,如果 s < w s<w s<w可以交换一下,从集合角度考虑,最优解一定是一个人拿了 a a a s s s b b b w w w,另一个人拿了 c c c s s s d d d w w w,因此可以考虑枚举第一个人拿 s s s的数目,然后 b , c , d b,c,d b,c,d贪心可以算出来。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll p,f;
ll cntw,cnts;
ll s,w;
int main()
{
    IO;
    int T;
    cin>>T;
    while(T--)
    {
        cin>>p>>f;
        cin>>cnts>>cntw;
        cin>>s>>w;
        if(s<w) swap(s,w),swap(cnts,cntw);
        ll maxs=p/s;
        ll res=0;
        for(int i=0;i<=min(maxs,cnts);i++)
        {
            ll a=i,b=min(cntw,(p-i*s)/w);
            ll d=min(f/w,cntw-b);
            ll c=min((f-d*w)/s,cnts-i);
            res=max(res,a+b+c+d);
        }
        cout<<res<<endl;
        
    }
    return 0;
}

C - Binary String Reconstruction

这题看错题了我晕😵
题目规则给你 w w w可以构造出 s s s,然后给你 s s s让你给出个 w w w结果看反了
注意字符串下标从1开始
然后就成了个分类讨论的模拟题。
如果s[i]=='1'说明w[i-x]=='1'||w[i+x]=='1'
如果s[i]=='0'说明w[i-x]=='0'&&w[i+x]=='0'
然后细节讨论一下即可

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int w[100010];
int main()
{
    IO;
    int T;
    cin>>T;
    while(T--)
    {
        int n,x;
        string s;
        cin>>s;
        n=s.size();
        cin>>x;
        s='0'+s;
        for(int i=0;i<=n+1;i++) w[i]=-1;
        bool ok=1;
        for(int i=1;i<=n;i++)
        {
            if(!ok) break;
            if(s[i]=='1')
            {
                if(i>x) 
                {
                    if(w[i-x]==0)
                    {
                        if(x+i<=n&&w[i+x]!=0) w[i+x]=1;
                        else ok=0;
                    }
                    else w[i-x]=1;
                }
                else if(x+i<=n) 
                {
                    if(w[i+x]==0) ok=0;
                    else w[x+i]=1;
                }
                else ok=0;
            }
            else
            {
                if(i>x) 
                {
                    if(w[i-x]==1) ok=0;
                    else w[i-x]=0;
                }
                if(x+i<=n)
                {
                    if(w[i+x]==1) ok=0;
                    else w[x+i]=0;
                }
            }
        }
        if(!ok) cout<<-1<<endl;
        else
        {
            for(int i=1;i<=n;i++)
            {
                if(w[i]!=-1) cout<<w[i];
                else cout<<0;
            }
            cout<<endl;
        }
    }
    return 0;
}

D - Zigzags

数据范围 n ≤ 3000 n\leq 3000 n3000那么 n 2 n^2 n2就可以解决
枚举 j , l j,l j,l维护 a [ i ] a[i] a[i]出现的次数, i < j i<j i<j扫一遍即可。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
const int N=3010;
int a[N],cnt[N];
int main()
{
    IO;
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            cnt[i]=0;//初始化
        }
        ll res=0;
        for(int j=1;j<=n;j++) 
        {
            ll s=0;//维护j~l中与<j中相同的对数
            for(int l=j+1;l<=n;l++)
            {
                if(a[l]==a[j]) res+=s;
                s+=cnt[a[l]];
            }
            cnt[a[j]]++;
        }
        cout<<res<<endl;
    }
    return 0;
}

E - Clear the Multiset

CF原题不过虽然题目是原题但是人是新人啊hhh
对于操作2除非将某一堆归零,否则即为无效操作
因此考虑对 [ l , r ] [l,r] [l,r]序列使用操作2直接让将某一个数清空,然后递归处理子问题即可详细可以参考知乎大佬讲解
铺设道路这题同样可以使用分治方法,之前用的是贪心。
该题前置题?积木大赛

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
const int N=5010;
int n;
int a[N];
int solve(int l,int r)
{
    if(l>r) return 0;
    if(l==r) return a[l]==0?0:1;
    
    int now=1e9+1;
    int k;
    for(int i=l;i<=r;i++)
        if(a[i]<now)
        {
            now=a[i];
            k=i;
        }
    for(int i=l;i<=r;i++) a[i]-=now;
    return min(now+solve(l,k-1)+solve(k+1,r),r-l+1);
}
int main()
{
    IO;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    cout<<solve(1,n)<<endl;
    return 0;
}

要加油哦~

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值