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

    Codeforces Round #700 (Div. 2)

    A - Yet Another String Game

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            string s; cin >> s;
            rep (i, 0, s.size() - 1)
                if (i & 1) s[i] = (s[i] == 'z' ? 'y' : 'z');
                else s[i] = (s[i] == 'a' ? 'b' : 'a');
            cout << s << '
    ';
        }
        return 0;
    }
    

    B - The Great Hero

    PII a[N];
     
    int main() {
        IOS;
        for (cin >> _; _; --_) {
            ll A, B; cin >> A >> B >> n; bool f = 1;
            rep (i, 1, n) cin >> a[i].fi;
            rep (i, 1, n) cin >> a[i].se;
            sort(a + 1, a + 1 + n);
            rep (i, 1, n)
                if (B > 0) {
                    int x = (B - 1) / a[i].fi + 1, y = (a[i].se - 1) / A + 1;
                    if (x < y) B = -1, f = 0;
                    else B -= y * a[i].fi;
                }
                else f = 0;
            cout << (f ? "YES
    " : "NO
    ");
        }
        return 0;
    }
    

    D - Painting the Array

    D1 和 D2 没啥区别代码就几个位置不一样

    本质是贪心, 对于最小, 那么肯定就是当能消得时候就放到另一个位置,

    那不能消呢? 那就贪心, 对于两堆的堆顶 x, y, next[i] 表示 位置i 的下一个 a[i] 出现的位置

    我们贪心放在 next[x] < next[y] 就好了, 下一个 x 马上要出现, 赶快覆盖掉

    对于最大, 也是一样, 能消就消, 贪心将 a[i] 放到 下一个较远的堆的上面

    int a[N], ne[N], h[N];
     
    int main() {
        IOS; cin >> n; VI x, y; k = n;
        rep (i, 1, n) cin >> a[i], ne[i] = n + 1;
        rep (i, 1, n) ne[h[a[i]]] = i, h[a[i]] = i;
        rep (i, 1, n) {
            if (x.empty()) x.pb(i);
            else if (a[i] == a[x.back()]) {
                if (!y.empty() && a[y.back()] == a[i]) --k;
                y.pb(i); x.pb(i);
            } else if (!y.empty() && a[i] == a[y.back()]) x.pb(i), y.pb(i);
            else if (y.empty()) x.pb(i);
            else if (ne[x.back()] < ne[y.back()]) x.pb(i);
            else y.pb(i);
        }
        cout << k;
        return 0;
    }
    
    int a[N], ne[N], h[N];
     
    int main() {
        IOS; cin >> n; VI x, y; k = n;
        rep (i, 1, n) cin >> a[i], ne[i] = n + 1;
        rep (i, 1, n) ne[h[a[i]]] = i, h[a[i]] = i;
        rep (i, 1, n) {
            if (x.empty()) x.pb(i);
            else if (a[i] == a[x.back()]) {
                if (!y.empty() && a[y.back()] == a[i]) y.pb(i);
                x.pb(i); --k;
            } else if (!y.empty() && a[i] == a[y.back()]) y.pb(i), --k;
            else if (y.empty()) y.pb(i);
            else if (ne[x.back()] < ne[y.back()]) y.pb(i);
            else x.pb(i);
        }
        cout << k;
        return 0;
    }
    

    C - Searching Local Minimum

    维护一个区间 [l, r], a[l] < a[l - 1] && a[r] < a[r + 1] 即可, 用二分去缩小区间大小

    int ask(int x) {
        cout << "? " << x << endl;
        cin >> x; return x;
    }
    
    int main() {
        IOS; cin >> n;
        int l = 1, r = n;
        while (l < r) {
            int mid = l + r >> 1, a = ask(mid), b = ask(mid + 1);
            if (a > b) l = mid + 1;
            else r = mid;
        }
        cout << "! " << l;
        return 0;
    }
    
  • 相关阅读:
    [Tips] Resolve error: server certificate verification failed.
    [Tips] bzr Import error
    NPAPI命休矣
    [Buzz Today]2013.08.18
    [Tips]Fix node.js addon build error: "gyp: binding.gyp not found"
    The.first.glance.at.linux.commands
    [Idea Fragments]2013.08.08
    Linux利器:WinSCP,Putty,pscp和psftp
    本博客已经迁移去http://blog.brightwang.com/
    将博客搬至CSDN
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/14399661.html
Copyright © 2011-2022 走看看