Codeforces Round #658 (Div. 2)

cf日常炸, 我42才进去

结果比赛刚结束, 我才调好D, 应该能过得, 毕竟现在不能交, 群里老哥说01背包, 那应该是稳得

cf终测完了, 过了, 心在流泪

A

#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(0); cin.tie(0);
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 a[1001], b[1001];
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    for (cin >> _; _; --_) {
        cin >> n >> m;
        memset(a, 0, sizeof a);
        rep (i, 1, n) {
            cin >> a[0];
            if (a[a[0]] == 0) a[a[0]] = b[a[0]] = i;
            else b[a[0]] = i; 
        }
 
        int x = 0;
        rep (i, 1, m) {
            cin >> b[0];
            if (x || a[b[0]] == 0) continue;
            x = b[0]; 
        }
 
        if (x) cout << "YES\n" << 1 << ' ' << x << '\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(0); cin.tie(0);
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 a[1001], b[1001];
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    for (cin >> _; _; --_) {
        cin >> n >> m;
        memset(a, 0, sizeof a);
        rep (i, 1, n) {
            cin >> a[0];
            if (a[a[0]] == 0) a[a[0]] = b[a[0]] = i;
            else b[a[0]] = i; 
        }
 
        int x = 0;
        rep (i, 1, m) {
            cin >> b[0];
            if (x || a[b[0]] == 0) continue;
            x = b[0]; 
        }
 
        if (x) cout << "YES\n" << 1 << ' ' << x << '\n';
        else cout << "NO\n";
    }
    return 0;
}

C1 & C2

我直接做的C2

一看2n, 就知道, 每一位需要两次就调好了

即 1, i

我们只用考虑第i位, 和第1位, 即可,

当然是倒序考虑, 你问为啥? 你正序刚调好, 就reverse了

手写一下, 会发现, 没旋转一次 i, 会使得第i位所指向的原数组的下标从正序到逆序, 即 i 和 n - i + 1 (是这么个意思, 具体的数字要另算)

每调好一位, 就调i - 1, 废话,

但是!, 我们的第i位指向的原数组的下标范围怎么变化的? 不就是缩小了1吗?

且还是从左端点或右端点缩小的!! (因为对应正序或逆序的端点阿)

所以 ++l, 或者--r不就完了, 具体见代码

#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(0); cin.tie(0);
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;
char a[N], b[N];
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    for (cin >> _; _; --_) {
        cin >> n >> a + 1 >> b + 1;
        VI ans;
 
        int l = 1, r = n, cur = 0;
        bool ls = 0;
        per(i, n, 1) {
            int idx = ls ? l : r, id = ls ? r : l;
 
            if ((a[idx] != b[i] && (cur & 1)) || 
                (a[idx] == b[i] && cur % 2 == 0)) {
                ls ? ++l : --r;
                continue;
            }
 
            if (a[id] != b[i] && cur % 2 == 0);
            else if (a[id] == b[i] && (cur & 1));
            else ans.pb(1);
 
            ls ? --r : ++l;
            ls = ls ? 0 : 1;
            ans.pb(i); ++cur;
        }
 
        cout << ans.size();
        for (int i : ans) cout << ' ' << i;
        cout << endl;
    }
    return 0;
}

D

md, 要不是cf刚开始进不去!!

01背包, 当出现 p[i] < p[i - 1], 那么直到出现p[j] > p[i], 否则这几个连续的数必须是在一组的

这不就是可行性的01背包吗? 有m个物体, 分别重b(即这一段连续的数的个数), 刚好凑成 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 IO ios::sync_with_stdio(0); cin.tie(0);
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 f[N], a[N], b[N], c[N];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    for (cin >> _; _; --_) {
        cin >> n; m = -1;
        rep(i, 1, n * 2) {
            cin >> a[i], f[i] = -1;
            if (a[i] < a[i - 1] && b[i - 1] == 1) b[i] = b[i - 1] + 1, c[m + 1] = a[i - 1];
            else if (b[i - 1] > 1 && a[i] < c[m + 1]) b[i] = b[i - 1] + 1;
            else b[i] = 1, c[++m] = b[i - 1];
        }

        c[++m] = b[n << 1];
        f[0] = 1;

        rep(i, 1, m) {
            per(j, n, c[i]) {
                if (f[j - c[i]] == 1) f[j] = 1;
            }
        }

        if (f[n] == 1) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}
posted @ 2020-07-22 01:04  洛绫璃  阅读(298)  评论(0编辑  收藏  举报