UVa 11292 The Dragon of Loowater,

在Loowater王国,一只突变的多头火龙威胁到整个王国的安全。国王必须依靠骑士们的力量来击败这只怪物,每位骑士的薪酬取决于其身高与所砍龙头大小的比配。本故事探讨了如何在资源有限的情况下,通过最优策略解决重大危机。

Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.

The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predators, the geese population was out of control. The people of Loowater mostly kept clear of the geese. Occasionally, a goose would attack one of the people, and perhaps bite off a finger or two, but in general, the people tolerated the geese as a minor nuisance.

One day, a freak mutation occurred, and one of the geese spawned a multi-headed fire-breathing dragon. When the dragon grew up, he threatened to burn the Kingdom of Loowater to a crisp. Loowater had a major problem. The king was alarmed, and called on his knights to slay the dragon and save the kingdom.

The knights explained: “To slay the dragon, we must chop off all its heads. Each knight can chop off one of the dragon’s heads. The heads of the dragon are of different sizes. In order to chop off a head, a knight must be at least as tall as the diameter of the head. The knights’ union demands that for chopping off a head, a knight must be paid a wage equal to one gold coin for each centimetre of the knight’s height.”

Would there be enough knights to defeat the dragon? The king called on his advisors to help him decide how many and which knights to hire. After having lost a lot of money building Mir Park, the king wanted to minimize the expense of slaying the dragon. As one of the advisors, your job was to help the king. You took it very seriously: if you failed, you and the whole kingdom would be burnt to a crisp


import numpy as np

Knight_number=10
Dragon_number=7
#np.random.seed(50)
Knight=np.sort(np.random.randint(low=1,high=11000,size=Knight_number))
Dragon=np.sort(np.random.randint(low=1,high=10000,size=Dragon_number))
print(Knight)
print(Dragon)

if Dragon[Dragon_number-1]>Knight[Knight_number-1]:
    print("Loowater is doomed! first")
else:
    knight_employed=0
    Cost=0
    
    for i in range(Dragon_number):
        while(Dragon[i]>Knight[knight_employed]):
            knight_employed =knight_employed+1
            if knight_employed==Knight_number:
                print("Loowater is doomed!")
                break
        Cost+=Knight[knight_employed]
        
        print("the dragon :",i,"by Knight:",knight_employed)
        knight_employed =knight_employed+1
        if knight_employed==Knight_number and i< Dragon_number-1:
            print("Loowater is doomed!")
            break
        print(Cost)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值