输入数据包括n+1行:
第一行为一个整数n(1 ≤ n ≤ 50),即棋盘的大小
接下来的n行每行一个字符串表示第i行棋盘的颜色,'W'表示白色,'B'表示黑色
输出小易会涂画的区域大小
3 BWW BBB BWB
3
n, *bw = open(0).read().split() n = int(n) def lamp(grid): B = [1 if i == 'B' else 0 for i in grid[0]] W = [1 if i == 'W' else 0 for i in grid[0]] m = max(max(B), max(W)) for j in range(1, n): tb = [1 if i == 'B' else 0 for i in grid[j]] tw = [1 if i == 'W' else 0 for i in grid[j]] B = [B[i] + 1 if tb[i] == 1 else 0 for i in range(n)] W = [W[i] + 1 if tw[i] == 1 else 0 for i in range(n)] m = max(m, max(B), max(W)) return m print(max(lamp(bw), lamp(list(zip(*bw))))) # 才发现题目只需要看列就行了。。。python的特色zip不能不用,如果有numpy这题可以写的更优美点