六一儿童节

Posted bernieloveslife

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了六一儿童节相关的知识,希望对你有一定的参考价值。

六一儿童节,老师带了很多好吃的巧克力到幼儿园。每块巧克力j的重量为w[j],对于每个小朋友i,当他分到的巧克力大小达到h[i] (即w[j]>=h[i]),他才会上去表演节目。老师的目标是将巧克力分发给孩子们,使得最多的小孩上台表演。可以保证每个w[i]> 0且不能将多块巧克力分给一个孩子或将一块分给多个孩子。

import sys
def solve(w,h):
    ws = sorted(w)[::-1]
    hs = sorted(h)[::-1]
    res = 0
    h = 0
    # print(ws,hs)
    for w in range(len(ws)):
        while h<len(hs):
            if ws[w]>=hs[h]:
                res += 1
                hs.pop(h)
                h=0
                break
            else:
                h += 1
    return res
 
a = sys.stdin.readline().strip()
h = sys.stdin.readline().strip().split()
b = sys.stdin.readline().strip()
w = sys.stdin.readline().strip().split()
# print(a,h,b,w)
for i in range(len(h)):
    h[i] = int(h[i])
for i in range(len(w)):
    w[i] = int(w[i])
print(solve(w,h))

以上是关于六一儿童节的主要内容,如果未能解决你的问题,请参考以下文章

HTML做一个节日页面六一儿童节纯HTML代码

HTML做一个节日页面六一儿童节纯HTML代码

儿童数据二叉树源代码

如何用Python欢度六一?

儿童节,和 AI 一起通关 “超级马里奥兄弟”

使用高级选择器执行以下任务的 JQuery 代码。 PS:儿童()不工作