Codeforces Round #700 (Div. 2)# Codeforces Round #700 (Div. 2) A ~ D1个人题解

Codeforces Round #700 (Div. 2)

比赛链接: Click Here

1480A. Yet Another String Game

因为Alice是要追求小,Bob追求大值,所以只要变为 az.

AC代码
int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    for (cin >> _; _--;) {
        string s;
        cin >> s;
        for (int i = 0; i < s.size(); ++i) 
            if (i % 2 == 0) {
                if (s[i] == 'a') cout << 'b';
                else cout << 'a';
            } else {
                if (s[i] != 'z') cout << 'z';
                else cout << 'y';
            }
        cout << "\n";
    }
    return 0;
}

1480B. The Great Hero

排序,对英雄伤害少的排前面,统计总共打败的敌人数即可

AC代码
using ll = long long;
int _;
struct node {
    ll a, b;
};
ll A, B;
bool cmp(node a, node b) {
    ll d1 = (a.b / A + a.b % A != 0) * a.a, d2 = (b.b / A + b.b % A != 0) * b.a;
    return d1 < d2;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    for (cin >> _; _--;) {
        int n, cnt = 0;
        cin >> A >> B >> n;
        vector<node> e(n);
        for (int i = 0; i < n; ++i) cin >> e[i].a;
        for (int i = 0; i < n; ++i) cin >> e[i].b;
        sort(e.begin(), e.end(), cmp);
        for (int i = 0; i < n; ++i) {
            while (B >= 1 && e[i].b >= 1) e[i].b -= A, B -= e[i].a;
            if (e[i].b <= 0) cnt++;
        }
        cout << (cnt == n ? "YES\n" : "NO\n");
    }
    return 0;
}

1480C. Searching Local Minimum

C题没做出来,待补。

1480D1. Painting the Array I

题意和思路来自网络

Codeforces Round #700 (Div. 2)# Codeforces Round #700 (Div. 2) A ~ D1个人题解

个人理解以后的AC代码
int _;
int a[210000];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int lst = 0, sum = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == a[i + 1]) {
            if (a[lst] != a[i])
                sum += 2;
            else {
                bool f = false;
                for (int j = i - 1; true; --j) {
                    if (a[j] != a[i] && a[j + 1] != a[i]) {
                        f = true;
                        break;
                    }
                    if (j == lst) break;
                }
                sum += f ? 2 : 1;
            }
            while (a[i] == a[i + 1]) ++i;
            lst = i;
        } else
            sum++;
        // cout << sum << "\n";
    }
    cout << sum << "\n";
    return 0;
}

1480D2. Painting the Array II

D2昨天没啥想法就被弃掉了(老菜鸡了)

顺便贴一下朋友的D2代码

AC代码
int _;
int a[100005], b[100005], ans[100005], now[100005], pre[100005];
int dfs(int x) {
    if (ans[x] != -1) return ans[x];
    if (x == 0) return 0;
    ans[x] = dfs(x - 1);
    if (pre[x]) ans[x] = max(ans[x], dfs(pre[x] + 1) + 1);
    return ans[x];
}
int main() {
    int T = 1;
    // cin>>T;
    while (T--) {
        int n, x = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
        for (int i = 1; i <= n; i++)
            if (a[i] != a[i - 1]) b[++x] = a[i];
        for (int i = 1; i <= x; i++) pre[i] = now[b[i]], now[b[i]] = i;
        memset(ans, -1, sizeof(ans));
        dfs(x);
        int mx = 0;
        for (int i = 1; i <= x; i++) mx = max(mx, ans[i]);
        cout << x - mx << endl;
    }
    return 0;
}
上一篇:2020/11/04 模拟赛 圆与圆之间的距离是不能一概而论的


下一篇:Java-Cookie三天免登陆学习