【打卡-蓝桥杯】Day 7

题目1:基础练习 芯片测试

【打卡-蓝桥杯】Day 7_第1张图片

解题思路

因为好的芯片多于坏的,所以如果是好芯片,那个被测试为 1 的 总数 > n/2

代码

n = int(input())
arr = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    count = 0
    for j in range(n):
        if arr[j][i] == 0: # 因为 坏芯片少,所以计算坏的
            count += 1
        if count >= n/2:
            break
    else:
        print(i+1, end=' ')

题目2:基础练习 龟兔赛跑预测

【打卡-蓝桥杯】Day 7_第2张图片

解题思路

(不是清华的是不是可以不用做)while Ture 跑就行了,判断下兔子要不要停,这里我用一个变量 记录需要停下几秒。

代码

v1, v2, t, s, l = map(int, input().split())
time = 0
rabbitStop = rabbitLen = turtleLen = 0
while True:
    time += 1
    # 乌龟 跑
    turtleLen += v2
    # 兔子跑
    if rabbitStop == 0:  # 兔子不停止 的时候
        rabbitLen += v1
        if rabbitLen - turtleLen >= t:
            rabbitStop = s
    else:
        rabbitStop -= 1
    if rabbitLen >= l or turtleLen >= l:
        break
if rabbitLen > turtleLen:
    print('R')
    print(time)
elif rabbitLen < turtleLen:
    print('T')
    print(time)
else:
    print('D')
    print(time)

题目3:基础练习 回形取数

【打卡-蓝桥杯】Day 7_第3张图片

解题思路

就是按照 回形 一步一步走,走到x,y越界 就拐弯,把上下左右四个情况写出来,循环

代码

m, n = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(m)]
vis = [[0 for _ in range(n)] for _ in range(m)]
x = 0
y = 0
stepNum = 0
while stepNum < m * n:  # 输出的数 小于 全部数量
    while x < m and vis[x][y] == 0:  # 往下走
        print(arr[x][y], end=' ')
        stepNum += 1
        vis[x][y] = 1
        x += 1
    x -= 1  # 循环多走了1步
    y += 1  # 拐弯
    while y < n and vis[x][y] == 0:  # 往右走
        print(arr[x][y], end=' ')
        stepNum += 1
        vis[x][y] = 1
        y += 1
    x -= 1
    y -= 1
    while x >= 0 and vis[x][y] == 0:  # 往上走
        print(arr[x][y], end=' ')
        stepNum += 1
        vis[x][y] = 1
        x -= 1
    x += 1
    y -= 1
    while y >= 0 and vis[x][y] == 0:  # 往左走
        print(arr[x][y], end=' ')
        stepNum += 1
        vis[x][y] = 1
        y -= 1
    x += 1
    y += 1

题目4:基础练习 报时助手

【打卡-蓝桥杯】Day 7_第4张图片

解题思路

(水一下)

代码

h, m = map(int, input().split())

time = {0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine',
        10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen',
        17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 21: 'twenty one', 22: 'twenty two',
        23: 'twenty three', 30: 'thirty', 40: 'forty', 50: 'fifty'}

if m == 0:
    print(time[h] + ' o\'clock')
else:
    print(time[h], end=' ')
    if 0 < m <= 20 or m == 30 or m == 40 or m == 50:
        print(time[m])
    elif 20 < m < 30:
        print(time[20] + ' ' + time[m - 20])
    elif 30 < m < 40:
        print(time[30] + ' ' + time[m - 30])
    elif 40 < m < 50:
        print(time[40] + ' ' + time[m - 40])
    else:
        print(time[50] + ' ' + time[m - 50])

你可能感兴趣的:(蓝桥杯,蓝桥杯,算法,python)