Codeforces Global Round 8

Posted heyuhhh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Global Round 8相关的知识,希望对你有一定的参考价值。

传送门

视频题解

先填坑,详细题解晚上晚些时候再补。先附上代码。


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;
}

以上是关于Codeforces Global Round 8的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Global Round 8 A. C+=(贪心)

Codeforces Global Round 8 E. Ski Accidents

Codeforces Global Round 8 E - Ski Accidents 拓扑

Codeforces Global Round 8 D. AND, OR and square sum(位运算)

Codeforces Global Round 1

Codeforces Global Round 8 D - AND, OR and square sum 尽量往大的数字上移动