zoukankan      html  css  js  c++  java
  • Codeforces Global Round 8

    传送门

    视频题解

    A. C+=

    显然选择增加较小的一个数更优。

    B. Codeforces Subsequences

    贪心构造即可,显然个数均分能使得最后乘积最大,因为要长度最小,所以枚举最小长度贪心就行。

    C. Even Picture

    类似于这样构造:

    D. AND, OR and square sum

    操作的本质相当于交换(0,1),显然所有的(1)尽可能跑到较大的数上面即可。

    E. Ski Accidents

    要用好每个点的出边为(2)并且删除总点数不超过(frac{4}{7})这个条件。
    考虑一颗三层的完全二叉树,总结点数为(7),第三层的结点数为(4),刚好符合条件。
    所以做法就是删除所有“第三层”的结点即可,容易证明“第三层”的结点不超过总结点的(frac{4}{7})
    具体做法就是按照拓扑序来求到达每个点的最长路来判断是否在“第三层”。

    F. Lamps on a Circle

    首先考虑如何求(R(n)),假设我们现在亮着(x)个灯泡,并且想要通过再点亮(k)个灯泡使得(x)增加,那么此时连续的亮着的段长度不超过(k-1),即至少(frac{x+k}{k-1})段。
    那么暗着的段也至少(frac{x+k}{k-1})段,故有不等式:

    • (frac{x+k}{k-1}+x+kleq n)

    求解得(xleq n-frac{n}{k}-k)。所以(x)至多为(n-lceilfrac{n}{k} ceil-k+1)
    找到(R(n))过后接下来就是构造最优方案,发现我们每次都使得连续亮着灯泡长度不超过(k-1)就行,所以将环(k)(k)个进行分割,并且每段第(k)个标记不可选,这样就能满足条件,每次操作过后亮着的灯泡都会增加,直到(geq R(n))就行。


    A. C+=
    /*
     * Author:  heyuhhh
     * Created Time:  2020/6/18 22:46:31
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
     
    void run() {
        int a, b, n;
        cin >> a >> b >> n;
        int ans = 0;
        while (a <= n && b <= n) {
            if (a < b) a += b;
            else b += a;
            ++ans;
        }
        cout << ans << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
    B. Codeforces Subsequences
    /*
     * Author:  heyuhhh
     * Created Time:  2020/6/18 22:51:51
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
     
    ll qpow(ll a, ll b) {
        ll res = 1;
        while (b) {
            if (b & 1) res = res * a;
            a = a * a;
            b >>= 1;
        }
        return res;   
    }
     
    const string str = "codeforces";
     
    void run() {
        long long k; cin >> k;
        int t;
        for (int i = 1;;i++) {
            if (qpow(i, 10) > k) {
                t = i - 1;
                break;
            }
        }
        for (int i = 0; i <= 10; i++) {
            ll res = 1;
            for (int j = 1; j <= i; j++) {
                res *= (t + 1);
            }
            for (int j = 1; j <= 10 - i; j++) {
                res *= (t);
            }
            if (res >= k) {
                string res = "";
                int now = 0;
                for (int j = 1; j <= i; j++) {
                    res += string(t + 1, str[now++]);
                }
                for (int j = 1; j <= 10 - i; j++) {
                    res += string(t, str[now++]);
                }
                cout << res << '
    ';
                return;
            }
        }
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
    C. Even Picture
    /*
     * Author:  heyuhhh
     * Created Time:  2020/6/18 23:14:47
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
     
    void run() {
        int n; cin >> n;
        int x = n;
        int nx = 0, ny = 0;
        vector <pii> ans;
        auto draw = [&] (int x, int y, int op) {
            if (op) ans.push_back(MP(x, y));
            ans.push_back(MP(x, y - 1));
            if (op) ans.push_back(MP(x, y + 1));
            if (op) ans.push_back(MP(x - 1, y));
            if (op) ans.push_back(MP(x - 1, y + 1));
            ans.push_back(MP(x + 1, y));
            ans.push_back(MP(x + 1, y - 1));
            return 1;
        };
        draw(nx, ny, 1), --n, ++nx, --ny;
        for (int i = n; i >= 1; i--) {
            draw(nx, ny, 0);
            ++nx, --ny;
        }
        cout << sz(ans) << '
    ';
        for (auto it : ans) {
            cout << it.fi << ' ' << it.se << '
    ';
        }
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
    D. AND, OR and square sum
    /*
     * Author:  heyuhhh
     * Created Time:  2020/6/18 23:56:37
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
     
    void run() {
        int n; cin >> n;
        vector <int> a(n);
        vector <int> cnt(20);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            for (int j = 0; j < 20; j++) {
                if (a[i] >> j & 1) {
                    ++cnt[j];
                }
            }
        }
        vector <int> b(n);
        for (int i = 0; i < 20; i++) {
            for (int j = 0; j < cnt[i]; j++) {
                b[j] += (1 << i);
            }
        }
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            ans += 1ll * b[i] * b[i];
        }
        cout << ans << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
    E. Ski Accidents
    /*
     * Author:  heyuhhh
     * Created Time:  2020/6/19 8:34:31
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 2e5 + 5;
     
    vector <int> rG[N];
    int n, m;
     
    void run() {
        cin >> n >> m;
        for (int i = 1; i <= n; i++) {
            rG[i].clear();
        }
        for (int i = 1; i <= m; i++) {
            int u, v; cin >> u >> v;
            rG[v].push_back(u);
        }
        vector <int> path(n + 1, 0);
        vector <int> ans;
        for (int i = 1; i <= n; i++) {
            for (auto j : rG[i]) {
                path[i] = max(path[j] + 1, path[i]);
            }
            if (path[i] == 2) {
                path[i] = -1;
                ans.push_back(i);
            }
        }
        cout << sz(ans) << '
    ';
        for (auto it : ans) {
            cout << it << ' ';
        }
        cout << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
    F. Lamps on a Circle
    /*
     * Author:  heyuhhh
     * Created Time:  2020/6/19 1:01:08
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e3 + 5;
     
    int n;
     
    int query(vector <int>& a) {
        cout << sz(a);
        for (auto it : a) {
            cout << ' ' << it;
        }
        cout << endl;
        int s; cin >> s;
        return s;
    }
     
    int answer() {
        cout << 0 << endl;
        exit(0);;
    }
     
    void run() {
        cin >> n;
        if (n <= 3) {
            answer();
        }
        int k, Max = -1;
        for (int i = 1; i <= n; i++) {
            if (n - i - (n + i - 1) / i + 1 > Max) {
                Max = n - i - (n + i - 1) / i + 1;
                k = i;
            }
        }
        vector <bool> ban(n + 1);
        for (int i = k; i <= n; i += k) {
            ban[i] = true;
        }
        vector <int> on(n + 1);
        while (1) {
            if (count(all(on), 1) >= Max) {
                answer();
            }
            int cnt = k;
            vector <int> q;
            for (int i = 1; i <= n && cnt; i++) {
                if (!ban[i] && !on[i]) {
                    on[i] = 1;
                    q.push_back(i);
                    --cnt;
                }
            }
            int s = query(q);
            cnt = k;
            while (cnt--) {
                on[s] = 0;
                ++s;
                if (s > n) s -= n;
            }
        }
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
  • 相关阅读:
    [LeetCode] 824. Goat Latin
    [LeetCode] 21. Merge Two Sorted Lists
    [LeetCode] 1021. Remove Outermost Parentheses
    [Note] Clipboard.js 使用
    [LeetCode] 665. Non-decreasing Array
    [LeetCode] 897. Increasing Order Search Tree
    [LeetCode] 136. Single Number
    [LeetCode] 822. Card Flipping Game
    [LeetCode] 922. Sort Array By Parity II
    [LeetCode] 965. Univalued Binary Tree
  • 原文地址:https://www.cnblogs.com/heyuhhh/p/13165806.html
Copyright © 2011-2022 走看看