本文主要是介绍CCF/CSP Python 20151202消除类游戏 20160902 火车购票,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
唉,好久没有来更新了,最近真的超多事情。后天就要考CCF,虽然平时练的挺好,但是上了考场上完全不一样的感觉,没有灵光乍现的话,我这脑子真的说不定。加油吧,novice!好运
#消除类游戏
m,n = map(int,input().split())
check = []
for i in range(m):check.append(list(map(int,input().split())))
ans = []
for i in check:ans.append(i[:])
#先按行扫描check是否可消除ans
#再按列扫描check是否可消除ans
#行
for i in range(m):j = 0while j < n:k = j+1while k < n and check[i][k] == check[i][j]: #扫描到不匹配的元素停止k += 1if k - j >= 3: #下标之差就是相同的元素个数ans[i][j:k] = [0] * (k-j)j = k
#列
for i in range(n):j = 0while j < m:k = j + 1while k < m and check[k][i] == check[j][i]:k += 1if k-j >= 3:for x in range(j,k):ans[x][i] = 0j = k
for i in ans:for j in i:print(j,end=' ')print()
#火车购票
#火车购票
seats = [[True]+[False for i in range(5)] for j in range(20)] # 座位初始化时为未占用状态False,占用状态True
n = int(input()) # 购票指令的数量
order = list(map(int,input().split()))
ans = []
for i in order:flag = False # 判断是否找到连续的座位temp = []j = 0while j < 20:if seats[j].count(False) >= i:flag = Truek = 1while k < 6 and i > 0:if seats[j][k] == False:seats[j][k] = Truei -= 1temp.append(j*5+k) # 如果找到了连续的座位,则计算座位号k += 1ans.append(temp)breakj += 1if flag:continuej = 0flag = False # 如果没有找到连续的座位号,就按行扫描,有空座位就坐while j < 20:for k in range(1,6):if seats[j][k] == False:seats[j][k] = Truei -= 1temp.append(j*5+k)if i == 0:ans.append(temp)flag = Truebreakif flag:breakj += 1
for i in ans:for j in i:print(j,end=' ')print()
这篇关于CCF/CSP Python 20151202消除类游戏 20160902 火车购票的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!