Codeforces Round 991 (Div. 3)

Codeforces Round 991 (Div. 3)

2024.12.6 rank 1559 rating 1314->1381

A

模拟

B

给定一数组,你可以任意操作:a[i-1]+1&&a[i+1]-1 或者 a[i-1]-1&&a[i+1]+1。问是否可以使数组全为相同的数字。

C

给定一大数,可任意将2->4,3->9,问是否可被9整除。

D

给定一大数,你可任意操作:将某一位数字减一将其与高位互换位置。问最大可成为的数字。

E

给定字符串a,b,c。当a,b不空时,随机选择a/b的第一个字母放到空字符串d后面。问将字符串d修改最少的字母和c相等。

------------------------独自思考分割线------------------------

  • 唯一有挑战性的题就是E吧

A 1点

1. 注意读完数据

B 2点

1.需要发现数字的转移只能在奇数/偶数项。

2.任意操作代表了可任意分配数字。则奇数偶数项分别求和分配即可。

C 3点

1.发现被9整除的数字数位之和为9的倍数。

2.在操作至多8个2和8个3看是否满足。因为超过8个是无意义的,则两侧枚举暴力。

3.赛时分类讨论数位和%9之后到达9的最小值分配2,3的数量,总感觉不太严谨的样子。可以hack一下试试。

D 2点

1.发现每个位置做多只和右侧9个数字有关。枚举每一位找到其可变成的最大值。

2.在贡献相同的情况下优先考虑左侧的数字。

E 2点

1.dp:f[i][j]:考虑a前i个字母,b前j个字母形成c前i+j个字母所需要修改的最小字母个数。

2.边界初始化

------------------------代码分割线------------------------

A

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n, m;
    cin >> n >> m;
    int cnt = 0;
    int f = 1;
    while (n--)
    {
        string s;
        cin >> s;
        if (f && m >= s.size())
        {
            m -= s.size();
            cnt++;
        }
        else
            f = 0;
    }
    cout << cnt << endl;
}

B

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    int s1 = 0, s2 = 0;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        if (i & 1)
            s1 += x;
        else
            s2 += x;
    }
    int f = 1;
    if (s1 % (n + 1 >> 1) || s2 % (n >> 1))
        f = 0;
    if (s1 / (n + 1 >> 1) - s2 / (n >> 1))
        f = 0;
    cout << (f ? "YES" : "NO") << endl;
}

C

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    string s;
    cin >> s;
    int sum = 0;
    int c2 = 0, c6 = 0;
    for (auto v : s)
    {
        if (v == '2')
            c2++;
        if (v == '3')
            c6++;
        sum += v - '0';
    }
    int x = sum % 9;
    int f = 0;
    auto ok1 = [&](int cnt)
    {
        return c2 >= cnt;
    };
    auto ok2 = [&](int cnt1, int cnt2)
    {
        return c2 >= cnt1 && c6 >= cnt2;
    };
    if (!x)
        f = 1;
    else if (x == 1)
    {
        if (c2 >= 4 || (c6 && c2))
            f = 1;
    }
    else if (x == 2)
    {
        if (c2 >= 8 || (c2 >= 5 && c6) || (c2 >= 2 && c6 >= 2))
            f = 1;
    }
    else if (x == 3)
    {
        if (ok1(3) || c6)
            f = 1;
    }
    else if (x == 4)
    {
        if (ok1(7) || ok2(4, 1) || ok2(1, 2))
            f = 1;
    }
    else if (x == 5)
    {
        if (ok1(2))
            f = 1;
    }
    else if (x == 6)
    {
        if (ok1(6) || ok2(3, 1) || c6 >= 2)
            f = 1;
    }
    else if (x == 7)
    {
        if (c2)
            f = 1;
    }
    else if (x == 8)
    {
        if (ok1(5) || ok2(2, 1))
            f = 1;
    }
    cout << (f ? "YES" : "NO") << endl;
}

D

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    string s;
    cin >> s;
    int n = s.size();

    for (int i = 0; i < n; i++)
    {
        int j = min(n - 1, i + 9);
        int jj = j;
        int maxw = 0;
        for (; j >= i; j--)
        {
            if (s[j] - (j - i) >= maxw)
            {
                maxw = s[j] - (j - i);
                jj = j;
            }
        }
        // bug(jj);
        if (jj == i)
            continue;
        j = jj;
        while (i - j)
        {
            swap(s[j], s[j - 1]);
            s[j - 1]--;
            j--;
        }
        // bug(s);
    }
    cout << s << endl;
}

E

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    string a, b, c;
    cin >> a >> b >> c;
    int n = a.size(), m = b.size();
    a = " " + a;
    b = " " + b;
    c = " " + c;
    vector<vector<int>> f(n + 1, vector<int>(m + 1, 1e18));

    f[0][0] = 0;
    for (int i = 1; i <= n; i++)
        f[i][0] = f[i - 1][0] + (a[i] != c[i]);
    for (int j = 1; j <= m; j++)
        f[0][j] = f[0][j - 1] + (b[j] != c[j]);
    // f[1][0] = a[1] != c[1];
    // f[0][1] = b[1] != c[1];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            f[i][j] = min(f[i - 1][j] + (a[i] != c[i + j]), f[i][j - 1] + (b[j] != c[i + j]));
            // bug3(i, j, f[i][j]);
        }
    cout << f[n][m] << endl;
}
posted @ 2024-12-07 18:55  Jkke  阅读(137)  评论(0)    收藏  举报