贪心4.0c++解析!

The holiday is coming, and you are a very caring parent who wants to give your children some small cakes during the holiday. However, each child can only give one piece of cake at most. For each child i, there is an appetite value g [i], which is the minimum size of a cake that can satisfy their appetite; And each cake j has a size s [j]. If s [j]>=g [i], we can allocate this cake j to child i, and this child will be satisfied. Your goal is to satisfy as many children as possible and output this maximum value.
Input format:
There are n and m in the first line, representing the number of children and Cake number
On the next line, enter the appetite value g [i] for n children.
Enter the size s [i] of m cakes in the last line.
Output format:
Number of children that can be satisfied
Sample Input 1:

3 2

1, 2, 3

1 1
Sample output 1:
1
Agreement:
1 ≤ n, m ≤ 100
1 ≤ g [i], s [i] ≤ 1000

Question Analysis
https://www.xinyoudui.com/courses/572#/pages/13963
Remember to sort after input,
Pay attention to array size

ACcode:
#include <bits/stdc++.h>

using namespace std;
char s[100010];
int oi;
//werygfiyweyguywegiugfyugrfuh
char e[28]={‘a’,‘a’,‘b’,‘c’,‘d’,‘e’,‘f’,‘g’,‘h’,‘i’,‘j’,‘k’,‘l’,‘m’,‘n’,‘o’,‘p’,‘q’,‘r’,‘s’,‘t’,‘u’,‘v’,‘w’,‘x’,‘y’,‘z’};
char op;
int a[1000010],b[1000010];
int t=1;
int idx=2;
int main()
{
op=‘a’;
long long re=0,ret=0;
int n,m,l=99999999;
scanf(“%d%d”,&n,&m);

for(int i=1;i<=n;i++)
{
	scanf("%d",&a[i]);

}
sort(a+1,a+1+n);
for(int i=1;i<=m;i++)
{
	scanf("%d",&b[i]);
}
sort(b+1,b+1+m);
int p=1;
for(int i=1;i<=m;i++)
{
	if(b[i]>=a[p])
	{
		ret++;
		p++;
	}
}

printf("%lld ",ret);

return 0;

}

假期将至,你是一位很有爱心的家长,想要在节假日的时候给你的孩子们一些小蛋糕。但是,每个孩子最多只能给一块蛋糕。对每个孩子 i,都有一个胃口值 g[i],这是能让孩子们满足胃口的蛋糕的最小尺寸;并且每块蛋糕 j,都有一个尺寸 s[j] 。如果 s[j] >= g[i],我们可以将这个蛋糕j 分配给孩子 i ,这个孩子会得到满足。你的目标是尽可能满足越多数量的孩子,并输出这个最大数值。

输入格式:

第一行一个n和m,表示孩子数和蛋糕数
接下来一行,输入n个孩子的胃口值g[i]。
最后一行输入m个蛋糕的尺寸s[i]。

输出格式:

能够满足的孩子数

样例输入1:

3 2 1 2 3 1 1

样例输出 1

1

约定:

1 ≤ n,m ≤ 100

1 ≤ g[i],s[i] ≤ 1000

输入完记得排序
注意数组大小

5 个赞