Codeforces Round #664 (Div. 2)

都是模拟题, 写慢了, 还因为细节wa了2次, 不太行

A

没处理好最后一种情况, wa1次

#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 IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
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;
 
int main() {
    IO;
    for (cin >> _; _; --_) {
        int r, g, b, w; cin >> r >> g >> b >> w;
        ll c = r + g + b + w;
        int cnt = (r & 1) + (g & 1) + (b & 1);
 
        if (cnt == 0 || cnt == 3) {
            cout << "YES\n";
        } else if (c & 1) {
            if (cnt == 2 && r && g && b) w += 3, cnt = 1;
 
            if (cnt == 2) cout << "NO\n";
            else if (w & 1) cout << "NO\n";
            else cout << "YES\n";
        } else cout << "NO\n";
    }
    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 IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
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;
 
int main() {
    IO;
        int x, y; cin >> n >> m >> x >> y;
        rep (j, y, m) cout << x << ' ' << j << '\n';
        per (j, y - 1, 1) cout << x << ' ' << j << '\n'; 
        int xx = x;
        rep (j, 1, m) {
            rep (i, x, n) {
                if (i == xx) continue;
                cout << i << ' ' << j << '\n';
            }
            per (i, x - 1, 1) {
                if (i == xx) continue;
                cout << i << ' ' << j << '\n';
            }
            if (x != 1) x = 1;
            else x = n;
        }
    return 0;
}

C

才2^9, 方法多了去了, 我这在 n,m较小的情况先 ll 也能跑

#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 IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
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;
VI b[201], c[201];
int a[201];
 
bool check(int k) {
    bool f = 1;
    rep(i, 1, n) {
        if ((1 << k) > a[i]) break;
        VI().swap(c[i]);
        for (int j : b[i])
            if (!((a[i] & j) >> k & 1)) c[i].pb(j);
        if (c[i].empty()) { f = 0; break; }
    }
    if (!f) return 0;
    rep(i, 1, n) {
        if ((1 << k) > a[i]) break;
        b[i].swap(c[i]);
    }
    return 1;
}
 
int main() {
    IO;
    cin >> n >> m;
    rep(i, 1, n) cin >> a[i], b[i].resize(m);
    rep(i, 0, m - 1) {
        cin >> b[1][i];
        rep(j, 2, n) b[j][i] = b[1][i];
    }
    sort(a + 1, a + 1 + n, greater<int>());
    int ans = 0;
    per(i, 30, 0) 
        if (!check(i)) 
            ans |= (1 << i);
    cout << ans;
    return 0;
}

D

细节没处理好, wa 1次

#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 IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
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;
VI a, b;

int main() {
    IO;
    cin >> n >> k >> m;
    rep(i, 1, n) {
        cin >> _;
        if (_ > m) a.pb(_);
        else b.pb(_);
    }

    ll ans = 0;
    if (a.empty() || a.size() == 1) {
        int i = 1;
        if (!a.empty()) ans += a[0], ++i;
        for (; i <= n; ++i) {
            if (b.empty()) break;
            ans += b.back(), b.pop_back();
        }
        cout << ans;
        return 0;
    }

    sort(all(a));
    sort(all(b));

    ans = a.back(); --n; a.pop_back();

    ll cur = 0;
    rep(i, 1, k + 1) {
        if (b.size() < i) break;
        cur += b[b.size() - i];
    }

    while (n >= k + 1 && !a.empty()) {
        if (a.back() <= cur) {
            ans += b.back();
            cur -= b.back();
            b.pop_back();
            if (b.size() >= k + 1) cur += b[b.size() - k - 1];
            --n;
        }
        else {
            ans += a.back(); a.pop_back();
            n -= (k + 1);
        }
    }

    rep(i, 1, n) {
        if (!b.empty())
            ans += b.back(), b.pop_back();
    }

    cout << ans;
    return 0;
}
posted @ 2020-08-13 00:36  洛绫璃  阅读(369)  评论(0编辑  收藏  举报