目录
[1.2 思路](#1.2 思路)
[1.3 代码实现](#1.3 代码实现)
[2.1 题目](#2.1 题目)
[2.2 思路](#2.2 思路)
[2.3 代码实现](#2.3 代码实现)
[3.2 思路](#3.2 思路)
[3.3 代码实现](#3.3 代码实现)
刷题汇总:传送门!
1、乒乓球匡
1.1题目

1.2 思路
这道题注意一下示例,<br/>其实是换行,只是示例没有很好的展示出来
根据题目知道,需要判定A、B两盒乒乓球中,A是否包含了B中所有类型的乒乓球,其中类型以大写字母表示。如果B盒中所有球的类型在A中都有,并且每种球的数量都不大于A,则输出"Yes";否则输出"No"即可。其实就是判断B是否是A的子集,那么用哈希表统计即可。
1)、利用哈希映射,统计A字符串中字符的频次;
(2)、再遍历利用哈希,减去B字符串出现的字符;
(3)、最后再次利用哈希查询数目是否满足题目要求,即查看哈希表中B中对应字符下标的数量是否小于0,小于说明,A中对应B的字符数量不足或者不存在B的字符。否则,输出"yes".
1.3 代码实现
cpp
#include <iostream>
using namespace std;
int main()
{
string A, B;
while (cin >> A >> B)
{
int hash[26] = { 0 };
for (auto ch1 : A)
{
hash[ch1 - 'A']++;
}
int flag = 1;
for (auto ch2 : B)
{
if (--hash[ch2 - 'A'] < 0)
{
flag = 0;
break;
}
}
cout << (flag ? "Yes" : "No") << endl;
}
return 0;
}

2、组队竞赛
2.1 题目

2.2 思路
读完题,知道让实现所有比赛组合的水平值最大,其中,每个队伍的水平值有该队伍第二高的选手水平值决定。那么,思路想到贪心法,尽可能让每个队伍都分到的第二高水平值的选手水平值高且接近,那么我们可以将每个选手的水平值进行sort排序,如5,2,8,5,1,5 排序后得到此时组队要水平值和最大,就把最大值放一组的最后,次大值作为该组第二个位置,再次大值作为第二组最大值,再将下一个值作为第二组的第二个位置,这样组成才是最大水平的和,所以最后我们就只需要拿去每一组第二个位置的值即可。

2.3 代码实现
cpp
#include <iostream>
#include<algorithm>
using namespace std;
const int N = 1e5+10;
int n;
long long arr[N*3];
int main()
{
cin >> n;
for(int i = 0;i < 3*n;i++) cin >> arr[i];
sort(arr,arr+n*3);
int index = n*3 - 2,count = 1;
long long ret = 0;
while(count++ <= n)
{
ret += arr[index];
index -= 2;
}
cout << ret <<endl;
return 0;
}

3、删除相邻数字的最大分数

3.2 思路

3.3 代码实现
cpp
#include <iostream>
using namespace std;
const int N = 1e4 + 10;
int hashcount[N] = { 0 };
int f[N];
int g[N];
int main()
{
int n;
cin >> n;
int a = 0;
for(int i = 0;i < n;i++)
{
cin >> a;
hashcount[a] += a;//统计a元素的分值和
}
//遍历哈希表
f[0] = g[0] = 0;
for(int i = 1;i < N;i++)
{
f[i] = hashcount[i] + g[i-1];
g[i] = max(f[i-1],g[i-1]);
}
//输出这两种情况的最大值即可
cout << max(f[N-1],g[N-1]) << endl;
return 0;
}

本篇完,下篇见!
