USACO: 1.2.5 Task gift1: Greedy Gift Givers (Python)

本文介绍了如何使用Python解决USACO竞赛中的1.2.5 Task gift1问题。通过贪心策略,解释了如何分配礼物以达到最优解,适合USACO参赛者和Python编程爱好者学习。
摘要由CSDN通过智能技术生成

 

 

"""
ID: oaimees1
LANG: PYTHON3
TASK: gift1
"""
fin = open ('gift1.in', 'r')
fout = open ('gift1.out', 'w')
lines = fin.read().splitlines()

NP = int(lines[0])
dic = {}
for i in range(1, NP + 1):
    """reading name of the group members"""
    dic[lines[i]] = 0

readingNum = NP + 1

for i in range(NP):
    ''' reading name of the gift giver'''
    gift_giver = lines[readingNum]
    readingNum += 1
    """reading the amount of money and the number of people"""
    tmp = lines[readingNum].split(' ')
    readingNum += 1
    amount = int(tmp[0])
    NGi = int(tmp[1])
    if NGi != 0:
        avg = int(amount / NGi)
        for j in range(NGi):
            """reading name of the gift reciver"""
           
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值