Educational Codeforces Round 94 (Rated for Div. 2)ABC题解

A. String Similarity

题意:

在这里插入图片描述
要求你构造一个串w。

思路:

在这里插入图片描述
对于这些字串,要满足相似,那么就保证每一个子串都至少有一个位置相似即可。
那么w【1】=s【1+0】.(保证 [ 1 , n ] [1,n] [1,n])
w【2】=s【2+1】.(保证 [ 2 , n + 1 ] [2,n+1] [2,n+1])
w【3】=s【3+2】.(保证 [ 3 , n + 2 ] [3,n+2] [3,n+2])
w【n】=s【n+n-1】.(保证 [ n , 2 n − 1 ] [n,2n-1] [n,2n1])

AC

#include <iostream>
#include <string>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        string s;cin>>s;
        string ans;
        for(int i=0; i<n; i++)ans+=s[i+i];
        cout<<ans<<endl;
    }
    return 0;
}

B. RPG Protagonist

题意:

有两个袋子,容量分别为 p p p f f f
有剑和盾。数量为 c n t s cnt_s cnts c n t w cnt_w cntw。容量为 s s s w w w

怎样可以装最多的剑和盾(总数)

思路:

枚举暴力。枚举装在第一个袋子的剑的数量。

AC

#include <iostream>
using namespace std;
typedef long long ll;
ll work2(ll &u, ll &tot, ll w){
    ll res=u/w;
    res=min(res,tot);
    u-=res*w;
    tot-=res;
    return res;
}
ll work(ll x, ll p, ll f, ll a, ll b, ll wa, ll wb){
    if(x*wa>p)return 0;
    ll ans=0;
    ans+=x;
    p-=x*wa;a-=x;
    ans+=work2(p,b,wb);
    ans+=work2(f,a,wa);
    ans+=work2(f,b,wb);
    return ans;
}
int main()
{
    int t;cin>>t;
    while(t--){
        ll a,b,wa,wb;
        ll p,f;
        cin>>p>>f;
        cin>>a>>b;
        cin>>wa>>wb;
        ll ans=0;
        if(wa>wb)swap(wa,wb),swap(a,b);
        for(int i=0; i<=a; i++){
            ans=max(ans,work(i,p,f,a,b,wa,wb));
        }
        cout<<ans<<endl;
    }
    return 0;
}

C - Binary String Reconstruction

题意:

有一个加密方法。现在给你密文(改变后的字符串),要求你把它变回原文(原字符串)。
在这里插入图片描述
其中w为原文。s为密文。

思路:

由于可能不存在情况,所以

  1. 先考虑0,
  2. 之后再考虑1(如果矛盾的话,那么就不存在),这里在1的基础下,就贪心的变化即可.

AC

#include <iostream>
#include <string>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;cin>>t;
    while(t--){
        string s;cin>>s;
        int x;cin>>x;
        int n=s.size();
        string ans;
        for(int i=0; i<n; i++)ans+='2';
        int flag=1;
        for(int i=0; i<n; i++){
            int p=i+1;
            if(s[i]=='0'){
                if(p+x<=n)ans[i+x]='0';
                if(p>x)ans[i-x]='0';
            }
        }
        for(int i=0; i<n; i++){
            int p=i+1;
            if(s[i]=='1'){
                int cnt=0;
                if(p>x){
                    if(ans[i-x]!='0')ans[i-x]='1';
                    else cnt++;
                }else cnt++;
                if(p+x<=n){
                    if(ans[i+x]!='0')ans[i+x]='1';
                    else cnt++;
                }else cnt++;
                if(cnt==2){
                    flag=0;
                    break;
                }
            }
        }
        if(!flag)cout<<-1<<endl;
        else {
            for(int i=0; i<n; i++)if(ans[i]=='2')ans[i]='1';//init
            cout<<ans<<endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值