AtCoder Beginner Contest 411

链接:https://atcoder.jp/contests/abc411

A – Required Length

算法:

    模拟。

思路:

    无。

关键代码:

void solve()
{
    int n;
    string s;
    cin >> s >> n;

    if (s.size() >= n)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

B – Distance Table

算法:

    模拟。

思路:

    无。

关键代码:

void solve()
{
    int n;
    cin >> n;
    vector<ll> a(n + 10, 0);
    for (int i = 0; i < n - 1; ++i)
        cin >> a[i];

    for (int i = 0; i < n - 1; ++i)
    {
        ll ans = 0;
        for (int j = i; j < n - 1; ++j)
        {
            ans += a[j];
            cout << ans << ' ';
        }

        cout << endl;
    }
}

C – Black Intervals

算法:

    模拟。

思路:

    考虑当前点的前后,判断是不是可以:

  • 构成一个新段。
  • 与前后两段合并。
  • 与前后其中一段合并。

关键代码:

void solve()
{
    int n, q;
    cin >> n >> q;

    vector<int> color(n + 10, 0);
    ll ans = 0;
    while (q--)
    {
        int x;
        cin >> x;

        if (!color[x])
        {
            color[x] = 1;

            if (x != 1 && color[x - 1] == 1 && x != n && color[x + 1] == 1)
                --ans;
            else if (color[x - 1] == 0 && color[x + 1] == 0)
                ++ans;
        }
        else
        {
            color[x] = 0;

            if (x != 1 && color[x - 1] == 1 && x != n && color[x + 1] == 1)
                ++ans;
            else if (color[x - 1] == 0 && color[x + 1] == 0)
                --ans;
        }

        cout << ans << endl;
    }
}

D – Conflict 2

算法:

    逆序模拟。

思路:

    从“最终服务器的内容”往前追溯,只看那些真正影响到最终结果的操作,其他操作一概跳过,不做任何处理。

    用一个 \(pos\) 标记“当前我们关心的是谁的字符串”,只有当操作的目标正好是 \(pos\) 指向的那台机器时,才执行“切换来源”或“收集追加”的逻辑。

    对于所有其他操作(正向它们会改别人的字符串,但最终没传到服务器),逆序时直接略过,既节省了拷贝,也避免了重复无效的计算。

关键代码:

void solve()
{
    int n, q;
    cin >> n >> q;

    vector<int> op(q + 10), p(q + 10);
    vector<string> s(q + 10);
    for (int i = 0; i < q; i++)
    {
        cin >> op[i] >> p[i];
        if (op[i] == 2)
        {
            cin >> s[i];
            reverse(all(s));
        }
    }

    ll pos = 0;
    string ans;
    for (int t = q - 1; t >= 0; t--)
    {
        if (op[t] == 1)
        {
            if (pos == p[t])
                pos = 0;
        }
        else if (op[t] == 2)
        {
            if (pos == p[t])
                ans += s[t];
        }
        else
        {
            if (pos == 0)
                pos = p[t];
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

E – E [max]

    还没补。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇