M-SOLUTIONS Programming Contest 2020 游记 (AB水题,CD模拟,E题DFS)

A - Kyu in AtCoder

水题

B - Magic 2

题意很好理解,但写的时候注意一下边界

void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while (a >= b) k--, b <<= 1;
    while (b >= c) k--, c <<= 1;
    cout << (k >= 0 ? "Yes" : "No");
}

C - Marks

模拟题

由于比较位是 \(a,b,c\)\(b,c,d\) 其中\(b,c\) 是一样的,所以我们只要比较更新的 \(a,d\) 大小即可

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for (ll &x : v) cin >> x;
    for (int i = k; i < n; ++i) cout << (v[i] > v[i - k] ? "Yes\n" : "No\n");
}

D - Road to Millionaire

同上,维护最新值即可

void solve() {
    ll a, b, c = 1000;
    for (cin >> a >> b; cin >> a; b = a)
        if (a > b) c += c / b * (a - b);
    cout << c;
}

E - M's Solution

比较麻烦的DFS 题,考虑一下细节

using ll    = long long;
const int N = 20;
struct node {
    ll x, y, w;
} e[N];
ll n, res[N][N], ans[N];
void dfs(int u, int cnt) {
    if (u == n) {
        ans[cnt] = min(ans[cnt], accumulate(res[n], res[n] + n, 0ll));
        return;
    }
    for (int i = 0; i < n; ++i) res[u + 1][i] = res[u][i];
    dfs(u + 1, cnt);
    for (int i = 0; i < n; ++i) res[u + 1][i] = min(res[u][i], e[i].w * abs(e[i].x - e[u].x));
    dfs(u + 1, cnt + 1);
    for (int i = 0; i < n; ++i) res[u + 1][i] = min(res[u][i], e[i].w * abs(e[i].y - e[u].y));
    dfs(u + 1, cnt + 1);
}
void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> e[i].x >> e[i].y >> e[i].w;
        ans[i]    = 1e18;
        res[0][i] = e[i].w * min(abs(e[i].x), abs(e[i].y));
    }
    dfs(0, 0);
    for (int i = 0; i <= n; ++i) cout << ans[i] << "\n";
}
posted @ 2021-04-27 21:59  RioTian  阅读(58)  评论(0编辑  收藏  举报