Codeforces Round 943 (Div. 3) 题解(A,B,C)

比赛链接:codeforces round 943 (div.3)

悲惨的表现分,rating 居然还加了,只能说我就是个废柴蒟蒻

A,B 简直不怎么动脑,但当我看到题解后才发现自己真的思维不如大佬

C ┭┮﹏┭┮ 构造构不出来呀!!

A. Maximize?

标签:暴力枚举+数学+数论

问题:给一个整数 x ,找出任意一个整数 y  ,使得  gcd( x , y ) + y  最大。(1\leqy<x)

比赛期间的代码:

#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve()
{
    int x;
    cin >> x;
    int tmp = 0, ans = 0;
    for (int i = 1; i < x; i++)
    {
        int cnt = gcd(x, i) + i;
        if (cnt > ans)
        {
            ans = cnt;
            tmp = i;
        }
    }
    cout << tmp << '\n';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

 大佬给的题解:

提示:

1.找出 gcd ( x , y ) + y 的上界    (核心思想)

2. gcd  ( x , y ) + y = gcd ( x - y , y ) + y

3. gcd ( x , y ) + y \leq x  \Rightarrow gcd ( x , y ) + y = x,是否有 y 呢?

解决思路:

其实要求 y 最大,即是指 gcd ( x , y ) = 1 ,所以 y (max) = x - 1

#include<iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int x;
		cin>>x;
		cout<<x-1<<"\n";
	}
}

B. Prefiquence

标签:贪心+双指针

问题:两个二进制字符串 a 和 b ,确定最大可能的数字 k  ,使得长度为 k  的字符串 a 的前缀是字符串 b 的子序列。字符串 a 的长度为 n ,字符串 b 的长度为 m。

$1\le n,m \le 2 \cdot 10^5$

#include <bits/stdc++.h>
 
using namespace std;
 
void solve()
{
    int n, m;
    cin >> n >> m;
    string a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = 0, j = 0; i < m; i++)
    { // i 对应 b ,j 对应 a
        if (a[j] == b[i])
        {
            ans++;
            j++;
        }
        // cout<<ans<<" ";
    }
    // cout<<'\n';
    cout << ans << '\n';
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

 C. Assembly via Remainders

标签:构造+数论

问题:给一个数组 $x_2,x_3,\dots,x_n$ ,找出任意一个数组 $a_1,\dots,a_n$,其中:

1. $1\le a_i\le 10^9$ 代表所有的 $1\le i\le n$

2. $x_i=a_i \bmod a_{i-1}$ 代表所有的 $2\le i\le n$

  大佬给的题解:

提示:$((a + b)\bmod a) = b$ 为 $0\le b < a$

解决思路:取 $a_1=1000$ ,因为 1000 比 $x_i$ 中的任何一个都要大,那么可以把 $a_i$ 当做 $a_{i-1}+x_i$ ,这样 $((a_{i-1}+x_i)\bmod a_{i-1})=x_i$ 将会被保留

a 的最大值最多为 $1000+500n$ ,小于 $10^9$

#include <bits/stdc++.h>

using namespace std;

void solve()
{
    int n;
    cin >> n;
    int s = 1000;
    cout << s << " ";
    for (int i = 2; i <= n; i++)
    {
        int x;
        cin >> x;
        s += x;
        cout << s << " ";
    }
    cout << '\n';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
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 ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

July.19th

感谢各位对我的支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值