Educational Codeforces Round 144 (Rated for Div. 2)(A~C)

A. Typical Interview Problem

从1开始,遇到3的倍数就在字符串后面加F,遇到5的倍数就在字符串后面加B,若遇到3和5的倍数,就加入FB,这样可以写一个无限长的字符串,给出一个长度最多为10的字符串,判断这个字符串是不是原字符串的子串。

思路:很容易发现原字符串的循环节是FBFFBFFB,直接暴力判断就可以。

AC Code:

#include <bits/stdc++.h>

typedef long long ll;
const int N = 2e5 + 5;
int t, n;
std::string s;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    std::cin >> t;
    while(t --) {
        std::cin >> n >> s;
        std::string ss = "FBFFBFFBFBFFBFFBFBFFBFFBFBFFBFFB";
        int pos = 0;
        bool flag = false;
        for(int i = 0; i < ss.length() - s.length() + 1; i ++) {
            // std::cout << ss[i] << '\n';
            int pos = i;
            for(int j = 0; j < s.length(); j ++) {
                if(ss[pos] != s[j])
                    break;
                pos ++;
                if(j == s.length() - 1)
                    flag = true;
            }
            if(flag)
                break;
        }
        std::cout << (flag ? "YES" : "NO") << '\n';
    }
    return 0;
}

os:当时赛时因为循环节就放了两个,不够长,wa了一发QWQ

B. Asterisk-Minor Template

给出两个字符串,如果两个字符串中有相同的字母,可以在另一个字符串有其他字母的位置添加“*”,一个“*”可以表示多个字符,也可以不表示字符,表示后的字符串内字母数量不能小于“*”数量,问有没有满足条件的表示法。例如样例中,“aaab”和“zzzb”可以用“*b”表示。

思路:因为“*”的数量不能大于字符数量,所以如果在字符串中隔一个加一个“*”一定不满足条件;可以得到以下结论:如果第一个字符或者最后一个字符相同,那直接用相同的这个字母加一个“*”即可;若都不相同,那就在字符串中找有无两个相邻的字母相同,若相同可以用“*xx*”表示,若不存在,则不能表示,输出-1。

AC Code:

#include <bits/stdc++.h>

typedef long long ll;
const int N = 2e5 + 5;
int t, n;
std::string a, b;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    std::cin >> t;
    while(t --) {
        std::cin >> a >> b;
        if(a[0] == b[0]) {
            std::cout << "YES" << '\n';
            std::cout << a[0] << '*' << '\n';
        }
        else if(a[a.length() - 1] == b[b.length() - 1]) {
            std::cout << "YES" << '\n';
            std::cout << '*' << b[b.length() - 1] <<  '\n';
        }
        else {
            std::map<std::string, int> mp;
            for(int i = 0; i < a.length() - 1; i ++) {
                std::string s = "";
                s += a[i];
                s += a[i + 1];
                mp[s] ++;
            }
            // for(auto [x, y] : mp)
            //     std::cout << x << ' ' << y << '\n';
            bool flag = false;
            std::string ans;
            for(int i = 0; i < b.length() - 1; i ++) {
                std::string s = "";
                s += b[i];
                s += b[i + 1];
                // std::cout << s << '\n';
                if(mp[s]) {
                    ans = s;
                    flag = true;
                    break;
                }
            }
            if(flag) {
                std::cout << "YES" << '\n';
                std::cout << '*' << ans << '*' << '\n';
            }
            else
                std::cout << "NO" << '\n';
        }
    }
    return 0;
}

C. Maximum Set

给出一个区间l和r,求最长的beautiful数组的长度,并计算区间内最长的beautiful数组有多少,答案对998244353取模。beautiful数组是指数组中任意两个数都有倍数关系的数组。

思路:最长的数组长度很好求,就是l一直乘2,一直到大于r为止。对于第二个答案,首先全乘2的数组会有一个区间,可以求得这样的数组的个数;然后分析可以将其中的2换成乘其他的数,乘3显然可以,如果乘4,那可以拆分为两个乘2,显然不满足最长的要求,再大的数类似,也不满足条件。所以易得,在乘2的序列中,尽可能将其中一个2换成3。这样的区间用同样的方法可以求得,并且对于相同开头的数组中,3乘在不同位置得到的数组不同,乘一下即可。

AC Code:

#include <bits/stdc++.h>

typedef long long ll;
const int N = 205;
int  t, l, r;

template<const int T>
struct ModInt {
    const static int mod = T;
    int x;
    ModInt(int x = 0) : x(x % mod) {}
    ModInt(ll x) : x(int(x % mod)) {} 
    int val() { return x; }
    ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
    ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
    ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
    void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
    void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
    void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
    void operator /= (const ModInt &a) { *this = *this / a; }
    friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x;}
    
    ModInt pow(int64_t n) const {
        ModInt res(1), mul(x);
        while(n){
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    
    ModInt inv() const {
        int a = x, b = mod, u = 1, v = 0;
        while (b) {
            int t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        if (u < 0) u += mod;
        return u;
    }
    
};
typedef ModInt<998244353> mint;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    std::cin >> t;
    while(t --) {
        std::cin >> l >> r;
        if(l * 2 > r) {
            std::cout << 1 << ' ' << r - l + 1 << '\n';
            continue;
        }
        int ans1 = 0, rr = l;
        while(rr <= r) {
            ans1 ++;
            rr <<= 1;
        }
        std::cout << ans1 << ' ';
        rr = r;
        int cnt = ans1 - 1;
        while(cnt --)
            rr >>= 1;
        mint ans2 = rr - l + 1;
        cnt = ans1 - 2, rr = r;
        while(cnt --)
            rr >>= 1;
        rr = rr / 3 - l + 1;
        ans2 += std::max(rr, 0) * (ans1 - 1);
        std::cout << ans2 << '\n';
    }
    return 0;
}

os:思路还是很好想到的,但是奈何我一直读假题了,,掉大分

"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值