python求助,28分

P1228 地毯填补问题

asdfjkd @ 2024-03-17 12:46:43

k = int(input())
x, y = map(int, input().split())

def fun (x1, y1, x2, y2, a, b):
    mid_x, mid_y = int((x1+x2)/2), int((y1+y2)/2)
    if mid_x>=a:
        if mid_y>=b:
            flag = 1
        else:
            flag = 2
    else:
        if mid_y >= b:
            flag = 3
        else:
            flag = 4
    if x2-x1 == 1:
        if flag==1:
            print('%d %d 1' %(x2, y2))
        elif flag==2:
            print('%d %d 2' %(x2, y2-1))
        elif flag==3:
            print('%d %d 3' %(x2-1, y2))
        else:
            print('%d %d 4' %(x2-1, y2-1))
    else:
        if flag==1:
            print('%d %d 1' %(mid_x+1, mid_y+1))
            fun(x1, y1, mid_x, mid_y, a, b)
            fun(x1, mid_y+1, mid_x, x2, mid_x, mid_y+1)
            fun(mid_x+1, y1, x2, mid_y, mid_x+1, mid_y)
            fun(mid_x+1, mid_y+1, x2, y2, mid_x+1, mid_y+1)
        elif flag==2:
            print('%d %d 2' %(mid_x+1, mid_y))
            fun(x1, y1, mid_x, mid_y, mid_x, mid_y)
            fun(x1, mid_y+1, mid_x, y2, a, b)
            fun(mid_x+1, y1, x2, mid_y, mid_x+1, mid_y)
            fun(mid_x+1, mid_y+1, x2, y2, mid_x+1, mid_y+1)
        elif flag==3:
            print('%d %d 3' %(mid_x, mid_y+1))
            fun(x1, y1, mid_x, mid_y, mid_x, mid_y)
            fun(x1, mid_y+1, mid_x, y2, mid_x, mid_y+1)
            fun(mid_x+1, y1, x2, mid_y, a, b)
            fun(mid_x+1, mid_y+1, x2, y2, mid_x+1, mid_y+1)
        else:
            print('%d %d 4' %(mid_x, mid_y))
            fun(x1, y1, mid_x, mid_y, mid_x, mid_y)
            fun(x1, mid_y+1, mid_x, y2, mid_x, mid_y+1)
            fun(mid_x+1, y1, x2, mid_y, mid_x+1, mid_y)
            fun(mid_x+1, mid_y+1, x2, y2, a, b)

fun(1, 1, 2**k, 2**k, x, y)

by defien_mian_main @ 2024-06-30 00:03:49

第29行有问题

fun(x1, mid_y+1, mid_x, x2, mid_x, mid_y+1)

这里x2应该改成y2,不然就是两个x坐标了 应该没有别的错了


|