目录
040:乒乓球框
041:组队竞赛
042:删除最大数字的相邻分数
040:乒乓球框
乒乓球筐__牛客网 (nowcoder.com)
题目:

题解:
哈希简单查询
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s1, s2;
    while (cin >> s1 >> s2) { // 未知组数的输⼊
        int hash[26] = { 0 };
        for (auto ch : s1) hash[ch - 'A']++;
        bool ret = true;
        for (auto ch : s2) {
            if (--hash[ch - 'A'] < 0) {
                ret = false;
                break;
            }
        }
        cout << (ret ? "Yes" : "No") << endl;
    }
    return 0;
}041:组队竞赛
组队竞赛_牛客笔试题_牛客网 (nowcoder.com)
题目:

题解:
排序后,每次取第二大的数
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n;
LL arr[N * 3];
int main() {
    cin >> n;
    for (int i = 0; i < 3 * n; i++) cin >> arr[i];
    sort(arr, arr + 3 * n);
    int pos = 3 * n - 2, count = 1;
    LL ret = 0;
    while (count++ <= n) {
        ret += arr[pos];
        pos -= 2;
    }
    cout << ret << endl;
    return 0;
}042:删除最大数字的相邻分数
删除相邻数字的最大分数_牛客题霸_牛客网 (nowcoder.com)
题目:

题解:
动态规划:力扣《打家劫舍》拓展~198. 打家劫舍 - 力扣(LeetCode)
将原数组改造一下,将相邻大小关系,变成相邻下标关系。

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N=10010;
int main() 
{
    int n=0;
    cin>>n;
    vector<int> arr(N);
    int x=0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        arr[x]+=x;
    }
    vector<int> dp(N);
    dp[0]=arr[0];
    dp[1]=max(arr[0],arr[1]);
    for(int i=2;i<N;i++)
    {
        dp[i]=max(dp[i-2]+arr[i],dp[i-1]);
    }
    cout<<dp[N-1]<<endl;
    return 0;
}


















