zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 198 个人题解(AB水题,C思维,D思维+全排列,E题DFS搜索,F懵逼)

    补题链接:Here

    A - Div

    题意:N 个不一样的糖,请问有多少种分法给 A,B两人

    水题,写几组情况就能知道输出 (N - 1) 即可

    B - Palindrome with leading zeros

    题意:给定一个字符串,问是否可以在字符串前加若干个 0 使字符串回文

    先判断一下字符串回文否?本身就回文就无需处理,不然字符串后面有几个 0 就加上多少,然后再判断

    C - Compass Walking

    题意:在一个二维坐标轴上,给定一个长度 R ,请问是否有最小步数(每步只能走 R,但坐标可以非整数)到达 ((X,Y))

    思路:

    假设 (d) 为 起点((0,0))((X,Y)) 的欧几里得距离,则容易想到以下三种情况

    • 答案为 (1) ,如果 (d = R)
    • 答案为 (2) ,如果 (d e R) 并且 (d < R)
    • (lceil frac{d}{R} ceil) ,其他情况

    其实这里 第一种情况和第三种情况可合并写:ceil(d / R)

    void solve() {
        double R, X, Y;
        cin >> R >> X >> Y;
        double d = sqrt(X * X + Y * Y);
        if (d < R) cout << 2;
        else
            cout << ceil(d / R);
    }
    

    D - Send More Money

    题意:给定 (3) 个字符串 (N_1,N_2,N_3) 试问是否有数字能代替某种字母使得 (N_1 + N_2 = N_3)

    思路:

    首先,如果出现 (10) 种以上的字母,那么肯定是无法解决的,直接输出 UNSOLVABLE 即可

    对于剩下的情况来说,可以尝试把数字分配给字母,然后 check 一下 (N_1 + N_2 = N_3)

    (10 ! = 3628800) 是可执行范围内

    注意别给首位分配 (0) 即可

    void solve() {
        map<char, int> ch;
        string s, t, w;
        cin >> s >> t >> w;
        for (char c : s) ch.emplace(c, 0);
        for (char c : t) ch.emplace(c, 0);
        for (char c : w) ch.emplace(c, 0);
        if (ch.size() > 10) {
            cout << "UNSOLVABLE";
            return;
        }
        int p[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        do {
            string a, b, c;
            int i = 0;
            for (auto it = ch.begin(); it != ch.end(); ++it, i++)
                it->second = p[i];
            for (char x : s) a.push_back(ch[x] + '0');
            for (char x : t) b.push_back(ch[x] + '0');
            for (char x : w) c.push_back(ch[x] + '0');
            ll A = stoll(a), B = stoll(b), C = stoll(c);
            if (a[0] != '0' && b[0] != '0' && c[0] != '0' && A + B == C) {
                cout << a << "
    "
                     << b << "
    "
                     << c << "
    ";
                return;
            }
        } while (next_permutation(p, p + 10));
        cout << "UNSOLVABLE";
    }
    

    E - Unique Color

    题意:

    思路:用 DFS 搜索一下即可

    // Murabito-B 21/04/12
    #include <bits/stdc++.h>
    using namespace std;
    using ll    = long long;
    const int N = 100005;
    int n, c[N], cnt[N], good[N];
    vector<int> to[N];
    void dfs(int u, int fa) {
        if (cnt[c[u]] == 0) good[u] = 1;
        cnt[c[u]]++;
        for (int i = 0, v; i < to[u].size(); i++)
            if ((v = to[u][i]) != fa) dfs(v, u);
        cnt[c[u]]--;
    }
    void solve() {
        cin >> n;
        for (int i = 1; i <= n; ++i) cin >> c[i];
        for (int i = 1, u, v; i < n; ++i) cin >> u >> v, to[u].push_back(v), to[v].push_back(u);
        dfs(1, 0);
        for (int i = 1; i <= n; ++i)
            if (good[i]) cout << i << "
    ";
    }
    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        solve();
        return 0;
    }
    

    F题表示是懵逼的,做不来

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    GoWeb-Gin 文件上载
    Node.JS + Mysql数据库
    Node.JS 项目打包 JXCore
    Express web框架 upload file
    hdoj 4430 Yukari's Birthday
    hdoj 4282 A very hard mathematic problem
    hdoj 3750 Guess Game
    hdoj 2199 Can you solve this equation?
    uva 11384 Help is needed for Dexter
    ios中fixed元素在滚动布局中的延时渲染问题
  • 原文地址:https://www.cnblogs.com/RioTian/p/14649066.html
Copyright © 2011-2022 走看看