21年计算机挑战赛Python组区域赛题目及个人解答(重置版)

1.乌鸦喝水

代码部分

# 计算机挑战赛--乌鸦喝水
x = int(input('请输入底边的边长:\n'))
y = int(input('请输入容器内水面距离瓶子口的距离:\n'))
z = 0
while 1:
    if x*x*y - 8*z < 2*x*x:
        print(f'需要投放{z}个石子乌鸦才能喝到水')
        break
    else:
        z = z + 1

2.竞赛学科分配

代码部分

# 计算机挑战赛--学科竞赛
people = int(input('输入想要参赛的人数:\n'))
subject = input('想要参加选拔的科目:\n')
list = [];total = 0;marks = [];
for i in range(people):
    id,g1,g2,g3,g4,g5,g6 = map(int,input().split())
    list.extend([[id,g1,g2,g3,g4,g5,g6]])
if subject == 'I':
    for i in range(people):
        List = list[i]
        x = List[2]
        y = List[3]
        new_total = x + y
        marks.append(new_total)
    count = marks.count(max(marks))
    if count == 1:
        List1 = list[marks.index(max(marks))]
        print(List1[0])
    else:
        List3 = []
        position = [index for index,value in enumerate(marks) if value == max(marks)]
        print(position)
        for i in position:
            List2 = list[i]
            List3.append(List2[0])
        List3.sort()
        print(List3)
        for i in List3:
            print(i)
if subject == 'B':
    for i in range(people):
        List = list[i]
        x = List[2]
        y = List[4]
        new_total = x + y
        marks.append(new_total)
    count = marks.count(max(marks))
    if count == 1:
        List1 = list[marks.index(max(marks))]
        print(List1[0])
    else:
        List3 = []
        position = [index for index,value in enumerate(marks) if value == max(marks)]
        for i in position:
            List2 = list[i]
            List3.append(List2[0])
        List3.sort()
        for i in List3:
            print(i)
if subject == 'H':
    for i in range(people):
        List = list[i]
        x = List[5]
        y = List[6]
        new_total = x + y
        marks.append(new_total)
    count = marks.count(max(marks))
    if count == 1:
        List1 = list[marks.index(max(marks))]
        print(List1[0])
    else:
        List3 = []
        position = [index for index,value in enumerate(marks) if value == max(marks)]
        for i in position:
            List2 = list[i]
            List3.append(List2[0])
        List3.sort()
        for i in List3:
            print(i)

3.机器人集合位置

代码部分

# 计算机挑战赛--集合位置
list = [];min_power = float('inf');v = 0;count = 1;sum = 0

#给出空列表,用于存储坐标值. 将初始最小能源消耗赋为无穷大,计数器与sum的值赋为0方便下方计算.

K = int(input('输入机器人的总数K(0<K<=100):\n'))
if K <= 0 or K > 100:
    print('错误!请确保K在正确范围之内!')
else:
    for i in range(K):
        x,y = map(int,input(f'输入第{i+1}个坐标值(x,y)(x<=10,y<=1000):\n').split())
        if x < 0 or x > 10 or y < 0 or y > 1000:
            print('错误!请确保(x,y)在正确范围之内!')
            break
        else:
            list.append([x,y])

#将用户输入的坐标值以子列表[]的形式添加到list列表中,形成一个二维列表,方便取用

    for i in list:
        list.remove(i)

#取出list列表中每一个坐标值,并暂时将其从列表中去除

        for o in range(K-1):
            a = abs(list[o][0] - i[0])
            b = abs(list[o][1] - i[1])
            sum = a + b + sum

#将去除后的list列表中的各个坐标依次拿出,并与取出的坐标作差,计算能量值

        if sum <= min_power:
            min_power = sum;sum = 0
        else:
            sum = 0

#如果得到的最小能量sum值小于min_power,将sum赋值给min_power,并将sum重新赋为0

        list.insert(v,i)
        v = v + 1

#将删掉的坐标按照原位返回到list列表中
    if min_power != float('inf'):
        print(min_power)
    else:
        print('出现错误!请检查输入')

4.产品质量抽查

代码部分

# 计算机挑战赛--产品质量抽查
N,M,K = map(int,input().split());list = [];v = 0;sum = 0;count = 0;
for i in range(N):
    list.append(input())
for i in list:
    list.remove(i)
    for o in i:
        if o == '1':
            count = count + 1
    for m in list:
        total = count
        for n in m:
            if n == '1':
                total = total + 1
            if total >= sum:
                sum = total
    count = 0
    list.insert(v,i)
    v = v + 1
print(sum)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值