Codeforces Round #671 (Div. 2)

A

人wa傻了, 审题不清, 两者选过的数字互不影响

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
 
const int N = 1e5 + 5;
 
int n, m, _, k;
char s[N];
 
int main() {
    IOS;
    for (cin >> _; _; --_) {
        cin >> n >> s + 1;
        int x = 0, y = 0, a = 0, b = 0;
        for (int i = 1; s[i]; ++i)
            if (i & 1) x += (s[i] - '0') & 1, y += !((s[i] - '0') & 1);
            else a += (s[i] - '0') & 1, b += !((s[i] - '0') & 1);
        if (x + y > a + b) 
            if (x) cout << 1 << '
';
            else cout << 2 << '
';
        else 
            if (b) cout << 2 << '
';
            else cout << 1 << '
';
    }
    return 0;
}

B

找规律, 下一个是由 上一个梯子放左下角, 上一个梯子放右上角, 和一个正方形组成

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
 
const int N = 1e5 + 5;
 
int n, m, _, k, x, y;
 
int main() {
    IOS;
    for (cin >> _; _; --_) {
        ll n, ls = 1; cin >> n; m = 0;
        while (n >= ls) {
            ++m; n -= ls;
            ls = (ls << 1) + (1ll << (m << 1));
        }
        cout << m << '
';
    }
    return 0;
}

C

贪心?

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
 
const int N = 1e5 + 5;
 
int n, m, _, k, z;
int a[1005];
ll q, p;
 
int main() {
    IOS;
    for (cin >> _; _; --_) {
        cin >> n >> m; q = p = z = 0;
        rep (i, 1, n) {
            cin >> a[i];
            if (a[i] == m) ++z;
            p += m - a[i];
        }
        if (z == n) cout << 0 << '
';
        else if (!p || z) cout << 1 << '
';
        else cout << 2 << '
';
    }
    return 0;
}

D_1 & D_2

贪心模拟一下

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
 
const int N = 1e5 + 5;
 
int n, m, _, k, x, y;
int a[N], b[N];
 
int main() {
    IOS; cin >> n;
    rep (i, 1, n) cin >> a[i];
    sort(a + 1, a + 1 + n);
    int l = 1;
    for (int i = 2; i <= n; i += 2) b[i] = a[l++];
    for (int i = 1; i <= n; i += 2) b[i] = a[l++];
    for (int i = 2; i <= n - 1; i += 2)
        m += (b[i - 1] > b[i] && b[i + 1] > b[i]);
    cout << m << '
';
    rep (i, 1, n) cout << b[i] << ' ';
    return 0;
}

E

构造

$ n = p_{1}^{c_1} * p_2^{c_2} * ... * p_k^{c_k} $

构造成 含有p_1的所有除数, p_1 * p_2, 含有p_2的所有除数, .... n

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
 
const int N = 1e6 + 5;
 
int n, m, _, k;
 
int main() {
    IOS;
    for (cin >> _; _; --_) {
        cin >> n; VI cnt, e; m = n;
        rep (i, 2, n / i)
            if (n % i == 0) {
                e.pb(i); cnt.pb(0);
                while (n % i == 0) ++cnt.back(), n /= i;
            }
        if (n > 1) e.pb(n), cnt.pb(1);
        if (e.size() == 1) {
            int res = e.back();
            while (cnt.back()--) cout << res << ' ', res *= e.back();
            cout << '
' << 0 << '
';
        }
        else if (e.size() == 2 && cnt[0] == 1 && cnt[1] == 1)
            cout << e[0] << ' ' << e[1] << ' ' << m << '
' << 1 << '
';
        else {
            vector<VI> ans(e.size()); unordered_set<int> factor;
            rep (i, 2, m / i) if (m % i == 0) factor.insert(i), factor.insert(m / i);
            per (i, e.size() - 1, 1) ans[i].pb(e[i] * e[i - 1]), factor.erase(e[i] * e[i - 1]);
            for (auto &i : factor)
                per (j, e.size() - 1, 0)
                    if (i % e[j] == 0) { ans[j].pb(i); break; }
            for (auto &i : ans) for (auto &j : i) cout << j << ' ';
            cout << m << '
' << 0 << '
';
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/2aptx4869/p/13707130.html