Bootstrap

牛客周赛 Round 50

小红的最小最大

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
const int N = 1e6 + 10;
typedef pair<int, int> pii;
 
void solve()
{
    int a, b, x;
    cin >> a >> b >> x;
    if (abs(a - b) < x) {
        cout << "YES" << '\n';
    } else {
        cout << "NO" << '\n';
    }
}
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
    // cin >> _;
    while (_ -- )
    {
        solve();
    }
    return 0;
}

小红的四则运算(easy) 

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
const int N = 1e6 + 10;
typedef pair<int, int> pii;
 
int w[4];
 
void solve()
{
    for (int i = 1; i <= 3; i ++ ) cin >> w[i];
    sort(w + 1, w + 3 + 1);
    if (w[1] == 1) {
        w[2] += w[1];
        if (w[3] == 1) {
            cout << 3 << '\n';
        } else {    
            cout << w[2] * w[3] << '\n';
        }
    } else {
        cout << w[1] * w[2] * w[3] << '\n';
    }
}
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
    // cin >> _;
    while (_ -- )
    {
        solve();
    }
    return 0;
}

小红的四则运算(hard) 

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
const int N = 1e6 + 10;
typedef pair<int, int> pii;

int w[4];

void solve()
{
    for (int i = 1; i <= 3; i ++ ) cin >> w[i];
    vector<int> ve;
    for (int i = 1; i <= 2; i ++ ) {
        if (w[i] == 1 || w[i + 1] == 1) {
            w[i + 1] += w[i];
            if (i == 2) {
                ve.push_back(w[i + 1]);
            }
        } else {
            ve.push_back(w[i]);
            if (i == 2) {
                ve.push_back(w[i + 1]);
            }
        }
    }
    int ans = 1;
    for (auto x : ve) {
        ans *= x;
    }
    cout << ans << '\n';
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
    // cin >> _;
    while (_ -- )
    {
        solve();
    }
    return 0;
}

小红的因式分解 

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
const int N = 1e6 + 10;
typedef pair<int, int> pii;

int a, b, c;
set<int> Sa, Sb;

void solve()
{
    cin >> a >> b >> c;
    Sa.clear();
    Sb.clear();
    for (int i = 1; i <= abs(a) / i; i ++ ) {
        if (abs(a) % i == 0) {
            Sa.insert(abs(a) / i);
            Sa.insert(i);
        }
    }
    if (c == 0) {
        for (auto a1 : Sa) {
            int a2 = a / a1;
            if (b == 0) {
                cout << a1 << ' ' << 0 << ' ' << a2 << ' ' << 0 << '\n';
                return ;
            } else {
                int b1 = 0, b2 = 0;
                if (b % a1 == 0) {
                    // b1 == 0;
                    b1 = 0;
                    b2 = b / a1;
                    cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << '\n';
                    return ;
                } 
                if (b % a2 == 0) {
                    b2 = 0;
                    b1 = b / a2;
                    cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << '\n';
                    return ;
                }
            }
        }

        for (auto x : Sa) {
            int a1 = -x;
            int a2 = a / a1;
            if (b == 0) {
                cout << a1 << ' ' << 0 << ' ' << a2 << ' ' << 0 << '\n';
                return ;
            } else {
                int b1 = 0, b2 = 0;
                if (b % a1 == 0) {
                    b1 = 0;
                    b2 = b / a1;
                    cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << '\n';
                    return ;
                } 
                if (b % a2 == 0) {
                    b2 = 0;
                    b1 = b / a2;
                    cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << '\n';
                    return ;
                }
            }
        }

    } else {
        for (int i = 1; i <= abs(c) / i; i ++ ) {
            if (abs(c) % i == 0) {
                Sb.insert(abs(c) / i);
                Sb.insert(i);
            }
        }

        for (auto x : Sa) {
            int a1 = x;
            int a2 = a / a1;
            for (auto y : Sb) {
                int b1 = y;
                int b2 = c / b1;
                if (a1 * b2 + a2 * b1 == b) {
                    cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << '\n';
                    return ;
                }
            }
        }

        for (auto x : Sa) {
            int a1 = -x;
            int a2 = a / a1;
            for (auto y : Sb) {
                int b1 = y;
                int b2 = c / b1;
                if (a1 * b2 + a2 * b1 == b) {
                    cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << '\n';
                    return ;
                }
            }
        }

        for (auto x : Sa) {
            int a1 = x;
            int a2 = a / a1;
            for (auto y : Sb) {
                int b1 = -y;
                int b2 = c / b1;
                if (a1 * b2 + a2 * b1 == b) {
                    cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << '\n';
                    return ;
                }
            }
        }

        for (auto x : Sa) {
            int a1 = -x;
            int a2 = a / a1;
            for (auto y : Sb) {
                int b1 = -y;
                int b2 = c / b1;
                if (a1 * b2 + a2 * b1 == b) {
                    cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << '\n';
                    return ;
                }
            }
        }

    }
    cout << "NO" << '\n';
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_ -- )
    {
        solve();
    }
    return 0;
}

小红的树上移动 

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
const int N = 1e6 + 10;
const int mod = 998244353;
typedef pair<int, int> pii;
 
int n, m, dp[N], dep[N], isend[N], lev[N];
vector<int> g[N], ve[N];
int mp[N][2]; // 0记录的是当前深度下叶子结点的个数, 1记录的是当前深度下非叶子的个数
 
int qmi(int a, int k, int p) {
    int res = 1;
    while (k) {
        if (k & 1) res = res * a % p;
        k >>= 1;
        a = a * a % p;
    }
    return res;
}
 
void dfs(int u, int fa) {
    dep[u] = dep[fa] + 1;
    m = max(m, dep[u]);
    int tot = 0;
    for (auto v : g[u]){
        if (v == fa) continue;
        ++ tot;
        dfs(v, u);
    }
    ve[dep[u]].push_back(u);
    if (! tot) isend[u] = 1;
}
 
void solve()
{
    cin >> n;
    for (int i = 1; i < n; i ++ ) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
 
    dfs(1, 0);
 
    for (int i = m; i >= 1; i -- ) {
        for (auto u : ve[i]) {
            // 深度为i的结点u,
            if (isend[u]) {
                mp[dep[u]][0] ++;
                dp[u] = 0;
            } else {
                // int j = i + 1;
                // for (auto v : ve[j]) {
                //     dp[u] += (dp[v] * qmi(ve[j].size(), mod - 2, mod) % mod);
                // }
                // dp[u] = (dp[u] + 1) % mod;
                mp[dep[u]][1] ++;
                dp[u] = (dp[u] + lev[dep[u] + 1] * mp[dep[u] + 1][1] % mod * qmi(ve[dep[u] + 1].size(), mod - 2, mod) % mod);
                dp[u] = (dp[u] + 1) % mod;
                lev[dep[u]] = dp[u];
            }
        }
    }
    cout << dp[1] << '\n';
}
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
    // cin >> _;
    while (_ -- )
    {
        solve();
    }
    return 0;
}

 

 

 

 

 

 

;