当前位置:网站首页>分饼干问题
分饼干问题
2022-06-25 14:20:00 【我不是萧海哇~~~~】
1.分配问题
有一群孩子和一堆饼干,每个孩子有一个饥饿度,°每个饼干都有一个大小。
每个孩子只能吃最多一个饼干,且只有饼干的大小大于孩子的饥饿度时,这个孩子才能吃饱。
求解最多有多少孩子可以吃饱。
输入输出样例
输入:
1 2
1 2 3
输出:2
Code:
int solve(vector<int> &children,vector<int> &cookies)
{
sort(children.begin(),children.end());
sort(cookies.begin(),cookies.end());
int ichi=0;
int icook=0;
while(ichi<children.size()&&icook<cookies.size())
{
if(children[ichi]<cookies[icook++])ichi++;
}
return ichi;
}
边栏推荐
- 还没弄明白微服务数据架构事务管理+ACID+一致性+CAP+BASE理论吗,看完彻底解决疑惑
- Installation and removal of MySQL under Windows
- None of the MLIR optimization passes are enabled (registered 2) solutions
- Variables, scopes, and variable promotion
- 英語中的九大詞性與九大時態
- 让PyTorch训练速度更快,你需要掌握这17种方法
- Sigmoid function sigmoid derivation
- Today in history: Netease was founded; The first consumer electronics exhibition was held; The first webcast in the world
- 现在股票开户用什么app最安全?知道的给说一下吧
- Why should programmers be softer?
猜你喜欢

K-line diagram 24 classic diagrams (shadow)

Stream竟然还有应用进阶学习?作为程序员的你知道吗

112页机器学习-数学基础回顾.pptx

两种方法实现pycharm中代码回滚到指定版本(附带截图展示)

完整详细的汇编实验报告

shell 数组
![[untitled] the CMD command window displays' NPM 'which is not an internal or external command](/img/db/b1ae4b0d1110af1e24887ba3b4fe16.jpg)
[untitled] the CMD command window displays' NPM 'which is not an internal or external command

Shell string variable

Les neuf caractéristiques de la parole et les neuf temps en anglais

Complete and detailed compilation of experimental reports
随机推荐
Encapsulating functions and event handling
Les neuf caractéristiques de la parole et les neuf temps en anglais
[untitled] the CMD command window displays' NPM 'which is not an internal or external command
Add a string at the input and textarea cursors
"Mobile cloud Cup" computing power network application innovation competition is in hot registration!
How does hash eagle, the founder of equity NFT, redefine NFT and use equity to enable long-term value?
China has made major breakthroughs in battery technology. Japan, South Korea and the United States are lagging behind. China has consolidated its leading edge
sigmoid函数sigmoid求导
Table de hachage, conflit de hachage
买基金在哪里开户安全?求指导
‘nvidia-smi‘ 不是内部或外部命令,也不是可运行的程序或批处理文件
Renix perf: detailed explanation of IP network performance test tools and test case parameters
作为一名软件测试工程师你认为怎么样才能保证软件质量?
哈希表、哈希冲突
Share the code technology points and software usage of socket multi client communication
How to choose a technology stack for web applications in 2022
重磅!国产 IDE 发布,由阿里研发,完全开源!(高性能+高定制性)
一次性总结:64个数据分析常用术语!
What is the difference between escape, encodeuri and encodeuricomponent?
Common formatting methods for amount numbers