zoukankan      html  css  js  c++  java
  • 20级训练赛Round #4

    给20级学弟学妹们带带榜单

    A - 凯少的动作序列

    枚举情况替换即可

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    void solve() {
        int n; string s;
        cin >> n >> s;
        int cnt = 0;
        for (int i = 1; i < n; ++i)if (s[i] != s[i - 1])i++, cnt++;
        cout << n - cnt;
    }
    int main() {
        ios::sync_with_stdio(false), cin.tie(nullptr);
        solve();
        return 0;
    }
    

    B - 凯少的秘密消息

    根据题意模拟

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    const int N = 1e5 + 10;
    map<string, int>mp;
    int cost[N], e[N], v[N];
    void solve() {
        int n, k, m;
        cin >> n >> k >> m;
        memset(v, 0x3f, sizeof(v));
        for (int i = 1; i <= n; ++i) {
            string s;
            cin >> s, mp[s] = i;
        }
        for (int i = 1, t; i <= n; ++i) {
            cin >> t;
            cost[i] = t;
        }
        for (int i = 1; i <= k; i++) {
            int n;
            cin >> n;
            while (n--) {
                int a;
                cin >> a;
                e[a] = i;
                v[i] = min(v[i], cost[a]);
            }
        }
        ll ans = 0;
        for (int i = 0; i < m; ++i) {
            string s; cin >> s;
            ans += v[e[mp[s]]];
        }
        cout << ans;
    }
    int main() {
        ios::sync_with_stdio(false), cin.tie(nullptr);
        solve();
        return 0;
    }
    

    C - 尚佬的投篮得分

    利用前缀和差值比较可以快速得到区间最大分数

    #include<bits/stdc++.h>
    using namespace std;
    const int N =  100000 + 10;
    int a[N], pre[N], cnt, mx;
    int main() {
        int n, k; cin >> n >> k;
        for (int i = 1; i <= n; ++i) cin >> a[i];
        for (int i = 1, x; i <= n; ++i) {
            cin >> x;
            pre[i] = pre[i - 1] + (1 - x) * a[i];
            cnt += x * a[i];
        }
        for (int i = k; i <= n; ++i) mx = max(mx, pre[i] - pre[i - k]);
        cout << cnt + mx;
        return 0;
    }
    

    D - 以旧换新

    可以DFS剪枝搜索,也可以排序以后比较ASCII值做交换

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    const int N = 1e5 + 10, mod = 1e9 + 7;
    void solve() {
        string a, b;
        cin >> a >> b;
        sort(a.begin(), a.end());
        for (int i = 0; i < a.length(); i++)
            for (int j = i + 1; j < a.length(); j++) {
                string t = a;
                swap(t[i], t[j]);
                if (stoll(t) > stoll(a) && stoll(t) <= stoll(b)) a = t;
            }
        cout << a << endl;
    }
    int main() {
        ios::sync_with_stdio(false), cin.tie(nullptr);
        solve();
        return 0;
    }
    

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

  • 相关阅读:
    DS博客作业02--线性表
    DS博客作业01--日期抽象数据类型设计与实现
    C语言博客作业06--结构体&文件
    C语言博客作业05--指针
    C语言博客作业04--数组
    DS博客作业08--课程总结
    DS博客作业07--查找
    06--图
    博客作业05--树
    DS博客作业01--日期抽象数据类型设计与实现
  • 原文地址:https://www.cnblogs.com/RioTian/p/14851339.html
Copyright © 2011-2022 走看看