前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【小码匠自习室】AtCoder ABC285解题报告

【小码匠自习室】AtCoder ABC285解题报告

作者头像
小码匠
发布2023-03-06 14:35:18
3160
发布2023-03-06 14:35:18
举报
文章被收录于专栏:小码匠和老码农

昨晚参加了一场线上赛,前段时间准备期末考试,有2周没摸键盘了,都有些生疏了。

上来想先签到C题,结果华丽丽遇到了坑,这个坑单独分享。之后有些小担心,就迅速刷掉了A

(避免鸭蛋,又被老码农嘲笑了,美其名曰:有舍才有得,小舍小得,大舍大得)

后来看了D题,最近刚学了拓扑排序,喜上眉梢,一次AC了D题。

E题:看完题目,感觉是动态规划题,剩下得时间不太多,就放弃了。(赛后补题)

B题:提点分吧,又随手刷掉了B题。(分分必争,其实像老码农说的,真的没必要,但还是不舍。。。)

A - Edge Checker 2

  • https://atcoder.jp/contests/abc285/tasks/abc285_a
小码匠代码
代码语言:javascript
复制
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';

void best_coder() {
    int a, b;
    cin >> a >> b;
    if (b == a * 2 || b == a * 2 + 1) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

void happy_coder() {
}

int main() {
    // 提升cin、cout效率
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // 小码匠
    best_coder();

    // 最优解
    // happy_coder();

    // 返回
    return 0;
}

B - Longest Uncommon Prefix

  • https://atcoder.jp/contests/abc285/tasks/abc285_b
小码匠代码
代码语言:javascript
复制
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';

void best_coder() {
    int n;
    string s;
    cin >> n >> s;
    for (int i = 1; i < n; ++i) {
        int ans = 0;
        for (int j = 0; j < n - i; ++j) {
            if (s[j] != s[j + i]) {
                ++ans;
            } else {
                break;
            }
        }
        cout << ans << endl;
    }
}

void happy_coder() {
}

int main() {
    // 提升cin、cout效率
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // 小码匠
    best_coder();

    // 最优解
    // happy_coder();

    // 返回
    return 0;
}

C - abc285_brutmhyhiizp

  • https://atcoder.jp/contests/abc285/tasks/abc285_c

单独分享,遇到了个坑,耽误了很多时间

D - Change Usernames

  • https://atcoder.jp/contests/abc285/tasks/abc285_d

板子题,解题思路就不赘述了

小码匠代码
代码语言:javascript
复制
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';


void best_coder() {
    int n;
    cin >> n;
    unordered_map<string, string> g(n);
    unordered_map<string, pair<int, int>> vp(n);
    for (int i = 0; i < n; ++i) {
        string a, b;
        cin >> a >> b;
        g[b] = a;
        ++vp[a].first;
        ++vp[b].second;
    }
    queue<string> q;
    for (auto i: vp) {
        if (i.second.first == 0) {
            q.push(i.first);
        }
    }
    int ans = vp.size();
    while (!q.empty()) {
        --ans;
        if (vp[q.front()].second == 0) {
            q.pop();
            continue;
        }
        q.push(g[q.front()]);
        q.pop();
    }
    if (ans == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

void happy_coder() {
}

int main() {
    // 提升cin、cout效率
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // 小码匠
    best_coder();

    // 最优解
    // happy_coder();

    // 返回
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-01-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小码匠和老码农 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • A - Edge Checker 2
    • 小码匠代码
    • B - Longest Uncommon Prefix
      • 小码匠代码
      • C - abc285_brutmhyhiizp
      • D - Change Usernames
        • 小码匠代码
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档