折纸测珠峰python程序_全国绿色计算大赛 模拟赛第二阶段 (Python)

第1关气温预测

def dailyTemps(temp_list):

result = []

for ca in range(0, len(temp_list)-1):

for i in range(ca + 1, len(temp_list)):

ind = temp_list[ca]

flag = 0

if (temp_list[i] > ind):

result.append(i - ca)

flag = 1

break

if (flag == 0):

result.append(0)

result.append(0)

return result

if __name__ == '__main__':

temp_list = [1,3,2]

print(dailyTemps(temp_list))

第2关折纸小游戏

def paperFolding(paper_info):

length = paper_info[0]

width = paper_info[1]

result = []

edge = hcf(length, width)

result.append(edge)

result.append(int(length*width/(edge*edge)))

return result

def hcf(x, y):

if x > y:

smaller = y

else:

smaller = x

for i in range(1, smaller + 1):

if ((x % i == 0) and (y % i == 0)):

hcf = i

return hcf

if __name__ == '__main__':

paper_info = [7, 3]

print(paperFolding(paper_info))

第3关渡口与船

def countOfShips(ferry):

result = 0

mp = [([0] * len(ferry[0])) for p in range(len(ferry))]

for i in range(len(ferry)):

for j in range(len(ferry[0])):

if (ferry[i][j] == "+"):

result += 1

if (judge(i + 1, j, ferry) or (judge(i - 1, j, ferry)) or (judge(i, j + 1, ferry)) or (judge(i, j - 1, ferry))):

if (judges(i + 1, j, mp) or (judges(i - 1, j, mp)) or (judges(i, j + 1, mp)) or (judges(i, j - 1, mp))):

result -= 1

mp[i][j] = 1

return result

def judge(x, y, ferry):

l = len(ferry)

w = len(ferry[0])

if (x < 0 or x >= l or y < 0 or y >= w): return False

if (ferry[x][y] == "+"):

return True;

else:

return False;

def judges(x, y, mp):

l = len(mp)

w = len(mp[0])

if (x < 0 or x >= l or y < 0 or y >= w): return False

if (mp[x][y] == 1):

return True;

else:

return False;

if __name__ == '__main__':

ferry = [

["+", "o", "o", "+", "o"],

["o", "o", "o", "o", "+"],

["o", "+", "o", "o", "+"],

["o", "+", "o", "o", "+"]

]

print(countOfShips(ferry))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值