A. 9x9

模拟

代码实现
#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b;
    scanf("%dx%d", &a, &b);
    
    int ans = a*b;
    cout << ans << '\n';
    
    return 0;
}

B. tcaF

模拟

代码实现
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll fact(ll n) {
    ll res = 1;
    for (int i = 1; i <= n; ++i) res *= i;
    return res;
}

int main() {
    ll x;
    cin >> x;
    
    int n = 1;
    while (1) {
        if (fact(n) == x) {
            cout << n << '\n';
            return 0;
        }
        n++;
    }
    
    return 0;
}

C. Snake Queue

可以开一个双端队列来维护每条蛇加进队列的坐标
对于操作2,可以开一个变量tx来记录队列中最后一条蛇的头部坐标

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    int q;
    cin >> q;
    
    deque<ll> x;
    ll tx = 0;
    
    rep(qi, q) {
        int type;
        cin >> type;
        if (type == 1) {
            int L;
            cin >> L;
            x.push_back(tx);
            tx += L;
        }
        else if (type == 2) {
            x.pop_front();
        }
        else {
            int k;
            cin >> k;
            --k;
            ll ans = x[k] - x[0];
            cout << ans << '\n';
        }
    }
    
    return 0;
}

D. Squares in Circle

可以分成4个对称的扇形来考虑
所以只需考虑 \(x \geqslant 1, y \geqslant 0\) 的扇形即可
统计这个扇形中的格点数可以二分或双指针

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    ll r;
    cin >> r;
    
    auto inside = [&](ll x, ll y) {
        x = x*2+1;
        y = y*2+1;
        return x*x+y*y <= r*r*4;
    };
    
    ll ans = 0;
    ll x = 0;
    for (ll y = r; y >= 0; --y) {
        while (inside(x+1, y)) x++;
        ans += x;
    }
    ans *= 4; ans++;
    
    cout << ans << '\n';
    
    return 0;
}

E. Square Price

这里的 \(k^2\) 比较麻烦,可以先把它拆开,算出第 \(i\) 种商品买第 \(k\) 个的费用为 \((2k-1)p_i\)
然后考虑贪心,尽可能买便宜的商品
可以二分求出最后买的商品价格的最大值

别忘了还需要考虑如果还有剩余的钱就每种商品尽可能再买一个
因为二分的只是商品价格上限,所以除了最后买的商品以外其他每种商品还是有可能可以继续买的

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    int n; ll m;
    cin >> n >> m;
    
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    
    ll tot, num;
    auto judge = [&](ll c) {
        tot = num = 0;
        rep(i, n) {
            ll k = ((c-1)/p[i]+1)/2; // (2k-1)*p < c
            if (k == 0) continue;
            if (m/k/k/p[i] == 0) return false;
            tot += k*k*p[i];
            num += k;
            if (tot > m) return false;
        }
        return true;
    };
    
    ll ac = 0, wa = m+1;
    while (abs(ac-wa) > 1) {
        ll wj = (ac+wa)/2;
        if (judge(wj)) ac = wj; else wa = wj;
    }
    
    judge(ac);
    num += (m-tot)/ac;
    cout << num << '\n';
    
    return 0;
}

F. Rated Range

直接将所有可能的 \(x\) 放一起来计算它们最后的rating
可以线段树上二分

代码实现
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int op(int a, int b) { return max(a, b); }
int e() { return 0; }

int mapping(int f, int x) { return x+f; }
int composition(int f, int g) { return f+g; }
int id() { return 0; }

int main() {
    int n;
    cin >> n;
    
    const int m = 500005;
    vector<int> initial(m);
    iota(initial.begin(), initial.end(), 0);
    lazy_segtree<int, op, e, int, mapping, composition, id> t(initial);
    
    auto lwb = [&](int x) {
        auto f = [&](int a) { return a < x; };
        return t.max_right(0, f);
    };
    
    rep(i, n) {
        int l, r;
        cin >> l >> r;
        r++;
        int li = lwb(l), ri = lwb(r);
        t.apply(li, ri, 1);
    }
    
    int q;
    cin >> q;
    rep(qi, q) {
        int x;
        cin >> x;
        int ans = t.get(x);
        cout << ans << '\n';
    }
    
    return 0;
}

G. Odd Even Graph

分层图计数

dp[i][j][k][e] 表示最后一层有 \(k\) 个点,奇数编号的层的总点数为 \(i\) 个,偶数编号的层的总点数为 \(j\) 个,总共有 \(e\) 条边

状态数为 \(O(N^5)\),转移数为 \(O(N^3)\),时间复杂度为 \(O(N^8)\),但常数比较小还是可以过的