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
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    CentOS 编译安装 MySQL5.7
    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了
    Linux里如何查找文件内容
    linux怎么模糊查找一个文件
    centos7下使用yum安装mysql
    centos下完全卸载mysql
    Linux下安装配置Nexus
    Linux下建立Nexus私服
    阿里云主机上安装jdk
    java war run
  • 原文地址:https://www.cnblogs.com/RioTian/p/14851339.html
Copyright © 2011-2022 走看看