2022团体程序设计天梯赛题解 Python

p1 签到题

print("I'm gonna win! Today!")
print('2022-04-23')


p2 L1-2 种钻石 (5 分)

n,v=list(map(int,input().split()))
print(n//v)


p3 L1-3 谁能进图书馆 (10 分)

a,b,x,y=list(map(int,input().split()))
ren=[0,x,y]
if x>=a and y>=a:
    print('%s-Y %s-Y' % (x, y))
    print('huan ying ru guan')
elif x>=b or y>=b:
    print('%s-Y %s-Y'%(x,y))
    print('qing %s zhao gu hao %s' % (ren.index(max(x, y)),ren.index( min(x, y))))
elif xy:
        print('%s-Y %s-N' % (x, y))
        print('%s: huan ying ru guan' % ren.index(max(x, y)))
    else:
        print('%s-N %s-Y' % (x,y))
        print('%s: huan ying ru guan'%ren.index(max(x, y)))
print(a,b,x,y,ren)


p4 L1-4 拯救外星人 (10 分)

a,b=list(map(int,input().split()))
ans=1
k=a+b
while k>1:
    ans*=k
    k-=1
print(ans)


p5 L1-5 试试手气 (15 分)

a=list(map(int,input().split()))
b=int(input())
k=[]
for i in range(6):
    kk=[]
    for i2 in range(1,7):
        if i2!=a[i]:
            kk.append(i2)
    kk.sort(reverse=True)
    k.append(kk)
ans=[]
for i in range(6):
    ans.append(k[i][b-1])
print(' '.join(map(str,ans)))


p6 L1-6 斯德哥尔摩火车上的题 (15 分)

a=input()
b=input()
s=''
s2=''
for i in range(1,len(a)):
    if int(a[i])%2==int(a[i-1])%2:
        s+=str(max(int(a[i]),int(a[i-1])))
#
for i in range(1,len(b)):
    if int(b[i])%2==int(b[i-1])%2:
        s2+=str(max(int(b[i]),int(b[i-1])))
if s==s2:
    print(s)
else:
    print(s)
    print(s2)


p7 L1-7 机工士姆斯塔迪奥 (20 分)

n,m,q=list(map(int,input().split()))
map1=[[0]*m for _ in range(n)]
print(map)
for i in range(q):
    t,c=list(map(int,input().split()))
    c-=1
    if t==0:
        for i2 in range(m):
            map1[c][i2]=1
    else:
        for i2 in range(n):
            print(i2,c)
            map1[i2][c]=1
ans=0
for i in range(n):
    ans+=map1[i].count(0)
print(ans)
for i in range(n):
    print(map1[i])


p8 L1-8 静静的推荐 (20 分)

n,k,s=list(map(int,input().split()))
mingdan=[]
for i in range(n):
    d=list(map(int,input().split()))
    if d[0]>=175:
        mingdan.append(d)

ming=[]
pi={}
for i in range(len(mingdan)):
    try:
        pi[mingdan[i][0]]+=1
    except:
        pi[mingdan[i][0]]= 1
for i in range(len(mingdan)):
    if mingdan[i][1] >= s:  # mingdan[i][0]>=175 and
        ming.append(mingdan[i][0])

pi2={}
for i in range(len(ming)):
    try:
        pi2[ming[i]]+=1
    except:
        pi2[ming[i]]= 1
ans=0
for i in pi2.keys():
    pi[i]-=pi2[i]
    ans+=pi2[i]
for i in pi.keys():
    if pi[i]>k:
        ans+=k
    else:
        ans+=pi[i]
print(ans)


p9 L2-2 老板的作息表 (25 分)

a=int(input())
qian=[]
hou=[]
def cmy(x):
    aa=list(map(int,x.split(":")))
    return aa[0]*3600+aa[1]*60+aa[2]
#
for k in range(a):
    c=input().split(' - ')
    qian.append(c[0])
    hou.append(c[1])
qian.sort(key=lambda x:cmy(x))
hou.sort(key=lambda x:cmy(x))
if qian[0]!='00:00:00':
    print('00:00:00 - %s'%qian[0])
for i in range(1,a):
    if hou[i-1]!=qian[i]:
        print('%s - %s'%(hou[i-1],qian[i]))
if hou[len(hou)-1]!='23:59:59':
    print('%s - 23:59:59'%hou[len(hou)-1])


p10 L2-1 插松枝 (25 分)

n,m,k=list(map(int,input().split()))
tui=list(map(int,input().split()))
tui.reverse()
hezi=[]
song=[]
while len(tui)!=0 or len(hezi)!=0:
    if len(song)==0:
        if len(hezi)==0:
            song.append(tui.pop())
        else:
            song.append(hezi.pop())
    elif len(hezi)!=0 and song[len(song)-1]>=hezi[len(hezi)-1]:
        # print(song[len(song) - 1], hezi[len(hezi)-1])
        song.append(hezi.pop())
    elif song[len(song)-1]>=tui[len(tui)-1]:
        # print(song[len(song)-1],tui[len(tui)-1])
        song.append(tui.pop())
    else:
        hezi.append(tui.pop())
    # 如果推送器上拿到的仍然不满足要求,就把拿到的这片堆放到小盒子里,继续去推送器上取下一片。

    if (len(hezi)==m and song[len(song)-1]

你可能感兴趣的:(笔记,算法,python)