B. Flag of Berland
这题还是不错的,题意是如果 可以分割成3条,R G B各一条,那就输出YES,每条可以包含多行,但是每条的行数必须相等
打了一大堆补丁,最后过了
n,m = map(int,raw_input().split()) mark = 1 s = [] for i in range(n): tmp = raw_input(); s.append(tmp); for c in range(m): if c + 1 < m and tmp[c] != tmp[c + 1]: mark = 0; r = 0 g = 0 b = 0 for a in s: for c in a: if c =='R': r = r + 1 if c == 'G': g = g + 1 if c == 'B': b = b + 1 if mark == 1: num = 1 w = [] for i in range(n): if i + 1 < n and s[i][0] == s[i + 1][0]: num = num + 1; else: w.append(int(num)) num = 1; for i in range(len(w)): if i + 1 < len(w) and w[i] != w[i + 1]: mark = 2; if mark == 1 and len(w) == 3 and r == g and g == b: print "YES" else: print "NO" else : for y in range(m): for x in range(n): if x + 1 < n and s[x][y] != s[x + 1][y]: mark = 2; break; if mark == 2: print "NO" else : num = 1 w = [] for i in range(m): if i + 1 < m and s[0][i] == s[0][i + 1]: num = num + 1 else: w.append(int(num)); num = 1; for i in range(len(w)): if i + 1 < len(w) and w[i] != w[i + 1]: mark = 2; if mark == 0 and len(w) == 3 and r == g and g ==b: print "YES" else: print "NO"
原文地址:http://www.cnblogs.com/pk28/
与有肝胆人共事,从无字句处读书。
欢迎关注公众号:
欢迎关注公众号: