Codeforces Round 925 (Div. 3) A-G 题解 | JorbanS

A - Recovering a Small String

string solve() {
    cin >> n;
    s = "aaa";
    n -= 3;
    if (n) s[2] += min(n, 25), n -= min(n, 25);
    if (n) s[1] += min(n, 25), n -= min(n, 25);
    if (n) s[0] += min(n, 25), n -= min(n, 25);
    return s;
}

B - Make Equal

string solve() {
    cin >> n;
    ll res = 0, sum = 0;
    for (int i = 1; i <= n; i ++) cin >> a[i], sum += a[i];
    sum /= n;
    for (int i = 1; i <= n; i ++) {
        res += a[i];
        if (res < sum * i) return no;
    }
    return yes;
}

C - Make Equal Again

int solve() {
    cin >> n;
    for (int i = 0; i < n; i ++) cin >> a[i];
    if (n == 1) return 0;
    int l = 0, r = n - 1;
    while (a[l] == a[l + 1] && l < n - 1) l ++;
    while (a[r] == a[r - 1] && r) r --;
    if (l > r) return 0;
    if (a[0] == a[n - 1]) return r - l - 1;
    return min(n - l - 1, r);
}

D - Divisible Pairs

ll solve() {
    cin >> n >> x >> y;
    for (int i = 0; i < n; i ++) {
        int t; cin >> t;
        a[i] = t % x, b[i] = t % y;
    }
    map<pii, int> mp;
    ll res = 0;
    for (int i = 0; i < n; i ++) {
        res += mp[{(x - a[i]) % x, b[i]}];
        mp[{a[i], b[i]}] ++;
    }
    return res;
}

E - Anna and the Valentine’s Day Gift

string solve() {
    cin >> n >> m;
    ll res = 0, c0 = 0;
    for (int i = 0; i < n; i ++) {
        int x; cin >> x;
        a[i] = 0;
        if (!x) {
            c0 ++;
            res ++;
            continue;
        }
        while (x % 10 == 0) x /= 10, a[i] ++;
        while (x) x /= 10, res ++;
    }
    if (c0 == n) return aa;
    sort(a, a + n);
    reverse(a, a + n);
    for (int i = 0; i < n; i ++)
        if (i & 1) res += a[i];
    return res > m ? bb : aa;
}

F - Chat Screenshots

题意:每个人将自己放到最前面,其他人顺序不变

不管第一个人,看后面 n − 1 n-1 n1 个人的顺序有没有冲突,即逆序对组成了环,拓扑排序即可

string solve() {
    cin >> n >> m;
    vector<vector<int>> e(n + 1);
    vector<int> d(n + 1);
    while (m --)
        for (int i = 0; i < n; i ++) {
            cin >> a[i];
            if (i > 1) e[a[i - 1]].emplace_back(a[i]), d[a[i]] ++;
        }
    queue<int> q;
    for (int i = 1; i <= n; i ++)
        if (!d[i]) q.push(i);
    int cnt = 0;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        cnt ++;
        for (auto v : e[u])
            if (-- d[v] == 0) q.push(v);
    }
    return cnt == n ? yes : no;
}

G - One-Dimensional Puzzle

挡板法

int qpow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = (ll)res * a % mod;
        a = (ll)a * a % mod;
        b >>= 1;
    }
    return res;
}

inline int inv(int x) { return qpow(x, mod - 2); }

inline int C(int a, int b) { return (ll)fac[a] * infac[b] % mod * infac[a - b] % mod; }

ll solve() {
    cin >> c1 >> c2 >> c3 >> c4;
    if (abs(c1 - c2) > 1) return 0;
    if (c1 == 1 && !c2 || !c1 && c2 == 1) return 1;
    if (!c1 && !c2) return !(c3 && c4);
    if (!c3 && !c4) return (c1 == c2) + 1;
    ll res = 0;
    if (c1 >= c2) {
        int l = c2 + 1, r = c1;
        res += (ll)C(l + c4 - 1, c4) * C(r + c3 - 1, c3);
    }
    if (c2 >= c1) {
        int l = c2, r = c1 + 1;
        res += (ll)C(l + c4 - 1, c4) * C(r + c3 - 1, c3);
    }
    return res % mod;
}

signed main() {
    FastIO
    *fac = 1;
    for (int i = 1; i <= M; i ++) fac[i] = (ll)fac[i - 1] * i % mod;
    infac[M] = inv(fac[M]);
    for (int i = M - 1; i >= 0; i --) infac[i] = (ll)infac[i + 1] * (i + 1) % mod;
    Cases
    cout << solve() << endl;
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 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
发出的红包

打赏作者

JorbanS

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值