zoukankan      html  css  js  c++  java
  • 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 << "
    ";
        }
        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
    " : "NO
    ");
        }
        return 0;
    }
    

    1480C. Searching Local Minimum

    C题没做出来,待补。

    1480D1. Painting the Array I

    题意和思路来自网络

    20210208132458

    个人理解以后的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 << "
    ";
        }
        cout << sum << "
    ";
        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;
    }
    

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    048——VUE中使用animate.css动画库控制vue.js过渡效果
    047——VUE中css过渡动作实例
    046——VUE中组件之使用动态组件灵活设置页面布局
    045——VUE中组件之父组件使用scope定义子组件模板结构
    004PHP文件处理——目录操作:glob rewinddir opendir readdir
    003PHP文件处理——目录操作:rename scandir
    044——VUE中组件之使用内容分发slot构建bootstrap面板panel
    Linux输出信息并将信息记录到文件(tee命令)
    linux下使用SVN上传项目
    linux下将文件上传到svn服务器
  • 原文地址:https://www.cnblogs.com/RioTian/p/14388479.html
Copyright © 2011-2022 走看看