[leetcode greedy]455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.
题意:把m块饼干分给n个孩子,每块饼干的尺寸为mi,每个孩子的要求尺寸为ni,最多可以使几个孩子满足?
思路:
排序,目标只分饼干,从小到大遍历饼干,只要有某个饼干可以满足某个孩子,就立马把饼干分出去,如果某块饼干不能满足最小的需求尺寸,立马舍弃这块饼干
class Solution(object):
def findContentChildren(self, g, s):
g.sort()
s.sort()
n,i = 0,0
for si in s:
if i == len(g):
break
if si >= g[i]:
n += 1
i += 1
return n
[leetcode greedy]455. Assign Cookies的更多相关文章
- 【leetcode】455. Assign Cookies
problem 455. Assign Cookies solution1: But, you should give each child at most one cookie. 对小朋友的满意程度 ...
- 【LeetCode】455. Assign Cookies 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...
- LeetCode:455. Assign Cookies
package Others; import java.util.Arrays; //Question 455. Assign Cookies /* Assume you are an awesome ...
- 455. Assign Cookies - LeetCode
Question 455. Assign Cookies Solution 题目大意:数组g的大小表示有几个小孩,每个元素表示小孩的食量,数组s的大小表示有多少个饼干,每个元素的大小表示每个饼干的大小 ...
- LeetCode 455. Assign Cookies (分发曲奇饼干)
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- 12. leetcode 455.Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- [LeetCode&Python] Problem 455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- LeetCode 455. Assign Cookies (C++)
题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...
- LeetCode: 455 Assign Cookies(easy)
题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...
随机推荐
- Linux/Unix 下自制番茄钟
习惯使用番茄工作法,在Linux上工作时也需要一个番茄钟. 安装一个Linux下番茄钟工作软件? 其实根本没必要,我们可以用Linux下经典的at命令实现一个简单的番茄钟. 安装AT 一般Linux基 ...
- bzoj 1044 [HAOI2008]木棍分割(二分+贪心,DP+优化)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1044 [题意] n根木棍拼到一起,最多可以切m刀,问切成后最大段的最小值及其方案数. ...
- Infinite Fraction Path(HDU6223 + bfs + 剪枝)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6223 题目: 题意: 给你一个长度为n的数字串,开始时你选择一个位置(记为i,下标从0开始)做为起点 ...
- Vue学习看这篇就够
Vue -渐进式JavaScript框架 介绍 vue 中文网 vue github Vue.js 是一套构建用户界面(UI)的渐进式JavaScript框架 库和框架的区别 我们所说的前端框架与库的 ...
- Framebuffer 驱动学习总结(二)---- Framebuffer模块初始化
---恢复内容开始--- Framebuffer模块初始化过程:--driver\video\fbmem.c 1. 初始化Framebuffer: FrameBuffer驱动是以模块的形式注册到系统 ...
- Meltdown论文翻译【转】
转自:http://www.wowotech.net/basic_subject/meltdown.html#6596 摘要(Abstract) The security of computer sy ...
- mysql备份的 三种方式【转】
备份的本质就是将数据集另存一个副本,但是原数据会不停的发生变化,所以利用备份只能回复到数据变化之前的数据.那变化之后的呢?所以制定一个好的备份策略很重要. 一.备份的目的 做灾难恢复:对损坏的数据进行 ...
- gc overhead limit exceeded内存问题
gc overhead limit exceeded 当出现这种问题的时候一般有两种思路 一.修改idea或者eclipse中的配置文件,将内存调到1024即可 二.在代码中通过system.gc 手 ...
- CSDN博客专家申请成功
又一个值得纪念的日子,上周六申请CSDN博客专家,今天中午审批通过.使用CSDN好几年了,从未想到能把博客一步步的写到这个地步. 曾经,写过一段博客,只是为了记录和分享.中间由于工作的变动和繁忙中断了 ...
- JavaWeb--中文乱码小结
JavaWeb--中文乱码小结 出处:http://chriszz.sinaapp.com0.纯粹html乱码: 换个editor吧(有时候notepad都比sublime_text好用),最好是在& ...