晶矿个数问题求助

12 views
Skip to first unread message

Junning Liu

unread,
Dec 30, 2018, 9:12:38 AM12/30/18
to cs101pku
没有定义函数,试了几个对了,但还是WA,不知道那个边界没有考虑到
k=int(input())
for i in range(k):
    n=int(input())
    mt=[['#']*(n+2)]+[list('#'+input()+'#')for y in range(n)]+[['#']*(n+2)]
    a=0
    b=0
    for i in range(1,n+1):
        for j in range(1,n+1):
            if mt[i][j]=='r'and mt[i-1][j]!='r' and mt[i][j-1]!='r':
                a+=1
                if mt[i+1][j]=='r':
                    mt[i-1][j]='r'
                    mt[i][j-1]='r'
            elif mt[i][j]=='b'and mt[i-1][j]!='b' and mt[i][j-1]!='b':
                b+=1
                if mt[i+1][j]=='b':
                    mt[i-1][j]='b'
                    mt[i][j-1]='b'
    print(a,b)

Hongfei Yan

unread,
Dec 31, 2018, 6:18:36 AM12/31/18
to cs10...@googlegroups.com
附件是测试数据。

--
您收到此邮件是因为您订阅了Google网上论坛上的“cs101pku”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到cs101pku+u...@googlegroups.com
要发帖到此群组,请发送电子邮件至cs10...@googlegroups.com
访问此群组:https://groups.google.com/group/cs101pku
要查看更多选项,请访问https://groups.google.com/d/optout
4101.rar
Reply all
Reply to author
Forward
0 new messages