zoukankan      html  css  js  c++  java
  • Codeforces Round #689 (Div. 2, based on Zed Code Competition)

    A - String Generation

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n >> m;
            rep (i, 1, n) cout << (char)(i < m ? 'a' : 'a' + (i - m) % 3); cout << '
    ';
        }
        return 0;
    }
    

    B - Find the Spruce

    dp, 根据下一层推就行, (O(n^2))

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n >> m; vector<VI> f(n + 2, VI(m + 2));
            ll ans = 0;
            rep (i, 1, n) cin >> s[i] + 1;
            per (i, n, 1) rep (j, 1, m) {
                if (s[i][j] == '.') continue;
                ans += f[i][j] = min(f[i + 1][j - 1], min(f[i + 1][j], f[i + 1][j + 1])) + 1;
            }
            cout << ans << '
    ';
        }
        return 0;
    }
    

    C - Random Events

    贪心

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n >> m;
            rep (i ,1, n) cin >> a[i], b[i] = a[i];
            sort(b + 1, 1 + n + b);
            int c = n;
            while (c && a[c] == b[c]) --c;
            double ans = c ? 0 : 1;
            rep (i, 1, m) {
                int r; double p; cin >> r >> p;
                if (r >= c) ans += (1 - ans) * p;
            }
            cout << setiosflags(ios::fixed) << setprecision(6) << ans << '
    ';
        }
        return 0;
    }
    

    D - Divide and Summarize

    贪心先把能找到的都找出来, (O(nlog^2n))

    void solve(int l, int r) {
        st.insert(b[r] - b[l - 1]);
        int mid = a[l] + a[r] >> 1;
        int c = upper_bound(a + l, a + r + 1, mid) - a;
        if (c - 1 == r) return;
        solve(l, c - 1); solve(c, r);
    }
     
    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n >> m; set<ll>().swap(st);
            rep (i, 1, n) cin >> a[i];
            sort(a + 1, a + 1 + n);
            rep (i, 1, n) b[i] = a[i] + b[i - 1];
            solve(1, n);
            rep (i, 1, m) cin >> k, cout << (st.count(k) ? "YES
    " : "NO
    ");
        }
        return 0;
    }
    

    E - Water Level

    分类讨论, 发现 x 的数据分为很小, 明显从 x 入手分类讨论, (O(n))

    int main() {
        IOS; ll k, l, r, t, x, y; cin >> k >> l >> r >> t >> x >> y;
        if (x > y) {
            if (k + y > r) k -= x, --t;
            if ((k - l) / (x - y) >= t) return cout << "Yes
    ", 0;
            else return cout << "No
    ", 0;
        } else {
            vector<bool> v(x);
            while (t > 0) {
                if (v[k % x]) return cout << "Yes
    ", 0;
                v[k % x] = 1;
                ll mx = min(t, (k - l) / x);
                t -= mx, k -= mx * x;
                if (t == 0) return cout << "Yes
    ", 0;
                --t, k += k + y > r ? -x : y - x;
                if (k < l) return cout << "No
    ", 0;
            }
        }
        return cout << "Yes
    ", 0;
    }
    
  • 相关阅读:
    intel 1211网卡驱动
    winform 右侧关闭按钮事件
    base64 教程
    js 预览图片 转base64
    docker常用命令
    docker安装
    jenkins集成sonar
    jenkins自动打包部署linux
    mac生成ssh公私匙
    jenkins统计单元测试的覆盖率
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/14128043.html
Copyright © 2011-2022 走看看