Codeforces Round 943 (Div. 3) B~E

B. Prefiquence

链接:Problem - B - Codeforces

算法:双指针

思路:一个l指针指向a字符串的第一个字母 r指针指向b的第一个字母,若l和r指向的字母相同 则双指针往后移动 并更新ans值为l指针 若l和r不相同 则移动r指针至第一个可以和l指针匹配的位置 直到l或者r指针跑到n或m

PS:赛时没想出来 寄

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
void solve() {
    ll n,m;cin>>n>>m;
    string a,b;cin>>a>>b;
    a=" "+a;
    b=" "+b;
    ll lcnt=1,rcnt=1;ll ans=0;
 
    while(lcnt<=n and rcnt<=m) {
        if(a[lcnt]==b[rcnt]) {
            lcnt++,rcnt++;
            ans=lcnt;
        }else if(a[lcnt]!=b[rcnt]){
            while(a[lcnt]!=b[rcnt] and rcnt<=m){
                rcnt++;
            }
        }
    }
    cout<<max(ans-1,0LL)<<"\n";
}
 
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

C. Assembly via Remainders

链接:Problem - C - Codeforces

算法:贪心

思路:看数据范围可以得知 取模后的值最多为500 所以即使500个500 也远远小于1e9 所以可以大胆的 从后往前跑 从1e9开始 每次减去要取模的值 肯定符合条件 

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
ll a[Q];ll ans[Q];
void solve(){
   ll n;cin>>n;
   for (ll i = 1; i <= n-1; i++)
   {
    cin>>a[i];
   }
   ll pre=1e9;
   ans[n]=1e9;
   for (ll i = n-1; i >= 1; i--)
   {
        ans[i]=pre-a[i];
        pre-=a[i];
   }
   for (ll i = 1; i <= n; i++)
   cout<<ans[i]<<" ";cout<<"\n";
}
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

D. Permutation Game

链接:Problem - D - Codeforces

算法:贪心

思路:每个人有一个起始位置 当我们走到每一个点的时候 我们都可以在这个地方停下直到游戏结束 可以肯定的是肯定有一个位置我们走到那个位置之后停下 直到游戏结束我们可以获得的分数最大 我们可以在起始位置停k轮 那我们将获得k*起始位置的分数 移动到下一个位置 我们将会获得 (k-1)*当前位置的分数+我从起始位置走到这里的分数 对于我能走到的每个位置 我们都可以这么做 每次取最大的ans值 看数据范围我们可以得知 k是1e9级别的 我们如果走k次 肯定会超时 但我们会发现 位置的数量只有2e5 这是可以接受的 所以我们可以开map记录一下我走过所有位置 当再次走到这个位置的时候 我们就可以结束循环了

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
ll a[Q],p[Q];
void solve(){
   ll n,k,b,s;cin>>n>>k>>b>>s;
   for (ll i = 1; i <= n; i++)
   {
    cin>>p[i];
   }
   for (ll i = 1; i <= n; i++)
   {
    cin>>a[i];
   }
   map<ll,ll>mp;
   ll lans=0,rans=0;
   ll sum=0;
   ll now=k;
    while(now--){
        if(mp[b]) break;
        sum+=a[b];
        mp[b]++;
        lans=max(lans,sum+a[b]*(now));
        b=p[b];
    }
    mp.clear();
    now=k;sum=0;
    while(now--){
        if(mp[s]) break;
        sum+=a[s];
        mp[s]++;
        rans=max(rans,sum+a[s]*(now));
        s=p[s];
    }
    // cout<<lans<<" "<<rans<<"\n";
    if(lans==rans) cout<<"Draw\n";
    else
    if(lans>rans) cout<<"Bodya\n";
    else cout<<"Sasha\n";
}
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

E. Cells Arrangement

链接:Problem - E - Codeforces

算法:构造

思路:一种验证可行的构造方法 为第一行的前n-2个单元格和最后一行的第二个和最后一个

(需要特判1和2的情况)如图为7的时候

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
void solve(){
   ll n;cin>>n;
   cout<<1<<" "<<1<<"\n";
   cout<<n<<" "<<n<<"\n";
   for (ll i = 2; i < n-1; i++)
   {
    cout<<1<<" "<<i<<"\n";
   }
   if(n>2)
   cout<<n<<" "<<2<<"\n";
   
   cout<<"\n";
}
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

  • 37
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值