当前位置:网站首页>Biscuit distribution

Biscuit distribution

2022-06-25 14:34:00 I'm not xiaohaiwa~~~~

1. Distribution problem
There's a bunch of kids and a bunch of biscuits , Every child has a hunger level ,° Each cookie has a size .
Each child can only eat at most one biscuit , And only when the size of the biscuit is greater than the child's hunger , The child will be able to eat .
How many children can eat at most .
I/o sample

 Input :
1 2
1 2 3
 Output :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;
}

原网站

版权声明
本文为[I'm not xiaohaiwa~~~~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251418133370.html