[笔试训练](十四)

 

目录

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;
}
  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_Zedd

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值