测试数据过了,但是其他的全错,不会改
查看原帖
测试数据过了,但是其他的全错,不会改
1283645
coloredCloud楼主2024/7/24 18:24
Only_UD = '|'
Only_LR = '-'
Block = '#'
ALL = 'O'
Empty = '.'

m,n = map(int,input().split())
pattern = []
for _ in range(m):
    pattern.append(list(input())[:n])

content = lambda a:pattern[a[0]][a[1]]
def ls():
    print()
    for i in range(m):
        print(''.join(pattern[i]))

def denote(x,y,signal):
    if set([content([x,y])] + [signal]) == set([Only_LR,Only_UD]):
        pattern[x][y] = ALL
    else:
        pattern[x][y] = signal

def spread(x,y,signal):
    current = [[x,y]]
    while True:
        if not current:
            break
        c = current.pop()
        if not content(c) in [signal,ALL,Block]:
            denote(c[0],c[1],signal)
            for direction in [(-1,0),(0,-1),(0,1),(1,0)]:
                new_x = c[0] + direction[0]
                new_y = c[1] + direction[1]
                if not new_x in range(m) or not new_y in range(n):
                    continue
                current.append([new_x,new_y])


spread(0,0,ALL)



for i in range(m):
    if content([i,0]) == Empty and content([i,n-1]) == ALL:
        spread(i,0,Only_LR)
        break
    elif content([i,0]) == ALL and content([i,n-1]) ==Empty:
        spread(i,n-1,Only_LR)
        break

for i in range(n):
    if content([0,i]) == Empty and content([m-1,i]) == ALL:
        spread(0,i,Only_UD)
        break
    elif content([m-1,i]) == ALL and content([0,i]) == Empty:
        spread(m-1,i,Only_UD)
        break



connection_of_leftright = any(content([i,0]) in [Only_LR,ALL] or content([i,-1]) in [Only_LR,ALL] for i in range(m))
connection_of_updown = any(content([0,i]) in [Only_UD,ALL] or content([-1,i]) in [Only_UD,ALL] for i in range(n))




q = int(input())
outp = []
for _ in range(q):
    x,y = map(int,input().split())
    out_r_x = not (0<=x<m)
    out_r_y = not (0<=y<n)
    if not out_r_x and not out_r_y:
        outp.append('yes' if pattern[x][y] == ALL else 'no')
        continue



    if out_r_x and -m<x and x<2*m:
        x = x % m
        outp.append('yes' if pattern[x][y] == Only_UD else 'no')
        continue

    elif not out_r_x and -n<y and y<2*n and out_r_y:
        y = y % n
        outp.append('yes' if pattern[x][y] == Only_LR else 'no')
        continue



    if out_r_x:
        if not connection_of_updown:
            outp.append('no')
            continue
        else:
            x = x % m

    if out_r_y:
        if not connection_of_leftright:
            outp.append('no')
            continue
        else:
            y = y % n

    outp.append('yes' if pattern[x][y] == ALL else 'no')

print('\n'.join(outp))

我感觉我这个应该没有问题了,但是测试点全错。大体思路是这样的:将只能通过上下/左右来到一个新的板块而到达的位置用不同的信号标记,然后如果一个点通过上下和左右两种方式均可到达,那么任何时候原点都可以直接到达它。如果一个点只能被左右到达,那只有它的板块在原点的左右时可以成功到达。上下同理。但是只有给出来的那组测试数据过了

2024/7/24 18:24
加载中...