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;
    }
    
  • 相关阅读:
    搭建Java 开发环境
    自己制作 Android Vector Asset 矢量图
    Manifest merger failed with multiple errors, see logs 问题处理
    Android 获取所在城市(不接入地图SDK,使用android自带的SDK定位)
    根据视频地址获取封面
    Git 的一些使用细枝末节
    关于onActivityResult方法不执行的问题汇总
    关于handler 和 looper 的问题
    关于action和category的认知区别
    关于activity的生命周期的随笔
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/14128043.html
Copyright © 2011-2022 走看看