文章目录
- 宜居星球改造计划
宜居星球改造计划
- yes no na 每个值为一个格子;
- 每天yes的值可以向上下左右扩展一个格子,将no改为yes;
- 矩形区域no是否可以全部转为yes,可以的话需要几天?不可以的话输出-1
- 输入:
yes yes no
no no no
yes no no
思路: - xxx
python:
def start_improve(data):
global total_days
row = len(data)
col = len(data[0])
yes_set = set()
no_set = set()
na_set = set()
for i in range(row):
for j in range(col):
if data[i][j] == "yes":
yes_set.add((i,j))
elif data[i][j] == "no":
no_set.add((i,j))
else:
na_set.add((i,j))
if not yes_set:
return -1
if not no_set:
return total_days
total_days += 1
for pos in list(yes_set):
pass
data = []
while True:
s = input().strip().split()
if s:
data.append(s)
else:
break
# 四个方向
direct = [(-1, 0), (1, 0), (0, 1), (0, -1), (0, 0)]
total_days = 0
# 改造
result = start_improve(data)