zoukankan      html  css  js  c++  java
  • Codeforces Round #688 (Div. 2)

    A - Cancel the Trains

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n >> m; VI a(n), b(m);
            for (auto &i : a) cin >> i;
            for (auto &i : b) cin >> i;
            int ans = 0;
            if (n > m) swap(n, m), swap(a, b);
            for (auto i : a) for (auto j : b) ans += i == j;
            cout << ans << '
    ';
        }
        return 0;
    }
    

    B - Suffix Operations

    就改一个数, 相当删了一个数

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n;
            rep (i, 1, n) cin >> a[i];
            ll ans = abs(a[n] - a[n - 1]), res = max(abs(a[2] - a[1]), ans);
            rep (i, 2, n - 1) {
                ll c = abs(a[i] - a[i - 1]); ans += c;
                umax(res, abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]) - abs(a[i + 1] - a[i - 1]));
            }
            cout << ans - res << '
    ';
        }
        return 0;
    }
    

    E - Dog Snacks

    dfs 遍历贪心就行哪个

    int dfs(int x, int fa) {
        int mx = 0, mi = N;
        for (auto y : e[x]) {
            if (y == fa) continue;
            int dep = dfs(y, x);
            if (x - 1) umin(mi, dep), umax(mx, dep);
            else
                if (dep > mx) mi = mx, mx = dep;
                else umax(mi, dep);
        }
        if (x - 1 && e[x].size() > 2) return umax(k, mx + 1), mi + 1;
        else if (x - 1) return 1 + mx;
        if (e[x].size() == 1) return max(k, mx);
        return max(k, max(mx, mi + 1));
    }
     
    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n; vector<VI>(n + 1).swap(e); k = 0;
            rep (i, 2, n) {
                int u, v; cin >> u >> v;
                e[u].pb(v); e[v].pb(u);
            }
            cout << dfs(1, -1) << '
    ';
        }
        return 0;
    }
    

    F - Even Harder

    f[i][k] 表示 唯一路径到达i, 且上一个点 j 能到达的最远点为 k 最少要清除平台的数量, 则

    (这个k是为了区分 j 的, 我们把所有的 j(j <= i) 按照能到大最远的点分了类, 说白了 i 是当前点, k是上一个点的集合)

    目标为 f[n][n]

    转移方程为 f[i][a[j] + j] = min(f[i][a[j][j]], f[j][i - 1] + j~i-1能到i的点的数量)

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n; rep (i, 1, n) cin >> a[i];
            rep (i, 2, n) {
                int c = 0;
                rep (j, i, n) f[i][j] = inf;
                per (j, i - 1, 1) if (j + a[j] >= i) umin(f[i][j + a[j]], f[j][i - 1] + c++);
                rep (j, i + 1, n) umin(f[i][j], f[i][j - 1]); //能到j, 肯定也能到 i~j-1
            }
            cout << f[n][n] << '
    ';
        }
        return 0;
    }
    
  • 相关阅读:
    Asp.Net中virtual、override理解
    SQL 知道字段名 全表搜索此字段属于哪个表
    C#中(int)a和Convert.ToInt32(a)的区别
    sql 查询表共多少列
    理解字节和字符
    C# IIS7.0+ Web.Config 配置Session过期时间
    Java版的扫雷游戏源码
    Activiti6.0教程 28张表解析 (三)
    Activiti6.0教程 Service用途剖析 (二)
    Activiti6.0教程 Eclipse安装Activiti Diagram插件(一)
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/14093333.html
Copyright © 2011-2022 走看看