python写的 第二个点测试点WA了 求助求助! 样例过了
查看原帖
python写的 第二个点测试点WA了 求助求助! 样例过了
558419
1eaves楼主2022/6/22 11:19

这是代码 大佬们帮忙看看

def setLight(a:list,x:int,y:int)->list:
    if a[x][y]==1:#如果是萤石
       for i in range(x-2,x+3):
           for p in range(y-2,y+3):
               try:
                  if a[i][p]==8:
                     a[i][p]=6 #6表示有光不刷怪
                  else: #如果不是暗处 是火把或者萤石或者光亮 跳过继续
                     continue
               except IndexError: #如果越界了 就跳过
                      continue
    elif a[x][y]==0:#如果是火把
       for i in range(x-2,x+3):
           for p in range(y-2,y+3):
               try:
                  if a[i][p]==8 and ( ((i==x-2 or i==x-1 or i==x+1 or i==x+2) and p==y) or ((p==y-2 or p==y-1 or p==y+1 or p==y+2) and i==x)
                                      or ((i==x-1 and p==y-1) or (i==x-1 and p==y+1) or (i==x+1 and p==y-1) or (i==x+1 and p==y+1)) ) :
                     a[i][p]=6
                  else: #如果不是暗处 是火把或者萤石或者光亮 跳过继续
                     continue
               except IndexError: #如果越界了 就跳过
                      continue
    return a

def cal(a:list,n:int)->int:
    mst=0
    for i in range(n):
        for p in range(n):
            if a[i][p]==8:
               mst+=1
    return mst

def search(a:list,n:int)->int:
   for i in range(n):  # 向右遍历
      for p in range(n):  # 向下遍历
          a=setLight(a,i,p)
   mster=cal(a,n)
   return mster

n, m, k = map(int, input().split())
dp = [[8 for i in range(n)] for p in range(n)] #无光为8
for i in range(0, m):
   o, p = map(int, input().split())
   dp[o-1][p-1] = 0  # 火把为0 萤石为1 有光为6
for i in range(0, k):
   o, p = map(int, input().split())
   dp[o-1][p-1] = 1  # 火把为0 萤石为1
print(search(dp,n))
2022/6/22 11:19
加载中...