重生之我会用C加加了


私信TA

用户名:dotcpp0602879

访问量:3699

签 名:

放纵是本性,克制是智慧。

等  级
排  名 414
经  验 4811
参赛次数 3
文章发表 21
年  龄 21
在职情况 学生
学  校 江西科技师范大学
专  业 大数据

  自我简介:

我唯一会的而且擅长的也就只有Python,如果不能在Python领域取得好的成绩,那人生还有什么意义呢!

解题思路:
这题20分白给啊!我前面一题就5分呜呜呜!!!
注意事项:

参考代码:



n=eval(input())

s=input()

temp=list(["0"]*201 for i in range(201))

result1,result2=[],[]

x0,y0=100,100

temp[x0][y0]=" " # 起点是空格 标记

result1.append(x0)

result2.append(y0)

for i in s:

    if i=="U":

        x0-=1

    elif i=="L":

        y0-=1

    elif i=="D":

        x0+=1

    elif i=="R":

        y0+=1

    result1.append(x0)

    result2.append(y0)

    temp[x0][y0]=" "

    

# 确定矩阵

result1.sort()

result2.sort()

h1,h2=result1[0],result1[-1]

L1,L2=result2[0],result2[-1]


temp2=temp[h1-1:h2+2]

tt=[]

for i in temp2:

    tt.append(i[L1-1:L2+2])


# 和BFS有点像    

qu=[[0,1],[1,0],[0,-1],[-1,0]]

for i in range(len(tt)):

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

        if tt[i][j]==" ":

            for k in qu:

                a,b=k

                if 0<=i+a<len(tt) and 0<=j+b<len(tt[0]) and tt[i+a][j+b]=="0":

                    tt[i+a][j+b]="*"


# 剩余部分

for i in range(len(tt)):

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

        if tt[i][j]=="0":

            tt[i][j]=" "



# 最后排除一下

for i in range(len(tt)):

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

        key=0

        if tt[i][j]==" ":

            for k in qu:

                a,b=k

                if 0<=i+a<len(tt) and 0<=j+b<len(tt[0]) and tt[i+a][j+b]=="*":

                    key+=1

                   

            if key==4:

                tt[i][j]="*"

for i in tt:

    print("".join(i))

    

 



def check(listx):

    def bfs(queue):

        for i in queue:

            x,y=i

            for j in qu:

                a,b=j

                if 0<=x+a<n and 0<=y+b<m and list1[x+a][y+b]!=1 and exist1[x+a][y+b]:

                    if m*(x+a)+y+b==z:

                        return 1

                    exist1[x+a][y+b]=0

                    queue.append([x+a,y+b])

        

    xx,z,r=listx[1:]

    x0,y0=xx//m,xx%m

    list1[x0][y0]=1

    x1,y1=r//m,r%m

    exist1=list([1]*m for i in range(n))

    exist1[x1][y1]=0

    qu=[[0,1],[1,0],[0,-1],[-1,0]]

    a=bfs([[x1,y1]])

    list1[x0][y0]=0

    if a:

        return 1

    return 0


def check2(nn):

    list2=[0,m-1,(n-1)*m,(n-1)*m+m-1]

    if nn in list2:

        return 1

    return 0

def check3(listx):

    xx,zz=listx[:2]

    listxx=[xx,zz]

    listxx.sort()

    aa,bb=listxx

    for i in range(aa+1,bb):

        x,y=i//m,i%m

        if list1[x][y]:

            return 0

    return 1

def dfs(step):

    if step-1==2 and check2(temp[2]):

        return 1

    if step-1==2:

        if temp[1]//m != temp[2]//m and  temp[1]%m != temp[2]%m:

            return 1

        if not check3(temp[1:]):

            return 1

    if step-1==3 and not check(temp):

        return 1

    if step-1==3:

        print(temp[1:])

        input()

        result[0]+=1

        return 1

    for i in range(n*m):

        if qq[i] and exist[i]:

            exist[i]=0

            temp[step]=i

            step+=1

            dfs(step)

            step-=1

            temp[step]=0

            exist[i]=1

n,m=map(int,input().split())

list1=[]

for i in range(n):

    list1.append(list(map(int,input().split())))


# qiang

qq=list(1 for i in range(n*m))

for i in range(n):

    for j in range(m):

        if list1[i][j]:

            qq[m*i+j]=0


temp=list(0 for i in range(4))

exist=list( 1 for i in range(n*m))

result=[0]

dfs(1)

print(result[0])


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区