(python)牛客周赛 Round 32

比赛链接:https://ac.nowcoder.com/acm/contest/75174#question

A.小红的01背包

思路:

V//x是看能装多少物品

再乘上每件物品的价格y就可以了

v,x,y = map(int,input().split())
print((v//x)*y)

B.小红的dfs

思路:

就是看每行每列不符合条件的有多少,先看第一行和第一列记录cnt1,再看第二行和第二列记录cnt2,再看第三行和第三列记录cnt3,看哪个符合条件最多。

list1 = []
for i in range(3):
    tmp = list(input())
    list1.append(tmp)
cnt1 = 0
cnt2 = 0
cnt3 = 0
if list1[0][0] != 'd': cnt1 += 1
if list1[0][1] != 'f': cnt1 += 1
if list1[0][2] != 's': cnt1 += 1
if list1[1][0] != 'f': cnt1 += 1
if list1[2][0] != 's': cnt1 += 1
if list1[1][0] != 'd': cnt2 += 1
if list1[1][1] != 'f': cnt2 += 1
if list1[1][2] != 's': cnt2 += 1
if list1[0][1] != 'd': cnt2 += 1
if list1[2][1] != 's': cnt2 += 1
if list1[2][0] != 'd': cnt3 += 1
if list1[2][1] != 'f': cnt3 += 1
if list1[2][2] != 's': cnt3 += 1
if list1[0][2] != 'd': cnt3 += 1
if list1[1][2] != 'f': cnt3 += 1
print(min(cnt1,cnt2,cnt3))

C.小红的排列生成

思路:

可以加1减1,先排列,那么我们只要看每次要达成条件每位的数应该如何变化就可以

n = int(input())
a = list(map(int,input().split()))
a.sort()
sum1 = 0
for i in range(1,n+1):
    sum1 += abs(i - a[i-1])
print(sum1)

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值