| | |
|
组别 | 诸侯 |
级别 | 征东将军 |
好贴 | 4 |
功绩 | 1845 |
帖子 | 5799 |
编号 | 622 |
注册 | 2004-7-7 |
| |
| | |
|
|
|
04 翻转积木
def get_list(file) :
[n, k] = map(int, file.readline().split(' '))
l = []
for i in range(0, n) :
l.append([ch for ch in file.readline().strip()])
return n, k, l
def turn_list(l) :
n = len(l)
for i in range(0, n) :
for j in range(n - 1, -1, -1) :
if '.' == l[i][j] :
for k in range(j - 1, -1, -1) :
if '.' != l[i][k] :
l[i][j] = l[i][k]
l[i][k] = '.'
break
def find_h(l, x, y, ch, n) :
for i in range(x + 1, x + n) :
if ch != l[y][i] :
return False
return True
def find_v(l, x, y, ch, n) :
for i in range(y + 1, y + n) :
if ch != l[i][x] :
return False
return True
def find_lt_rb(l, x, y, ch, n) :
for i in range(1, n) :
if ch != l[y + i][x + i] :
return False
return True
def find_rt_lb(l, x, y, ch, n) :
for i in range(1, n) :
if ch != l[y + i][x - i] :
return False
return True
def find(l, x, y, ch, n) :
size = len(l)
d = {'h': False, 'v': False, 'r': False, 'l': False}
if size - y >= n :
d['v'] = True
if size - x >= n :
d['h'] = True
d['r'] = True
if x >= n - 1 :
d['l'] = True
else :
if size - x >= n :
d['h'] = True
r = False
if d['h'] :
r = find_h(l, x, y, ch, n)
if d['v'] and not r :
r = find_v(l, x, y, ch, n)
if d['r'] and not r :
r = find_lt_rb(l, x, y, ch, n)
if d['l'] and not r :
r = find_rt_lb(l, x, y, ch, n)
return r
def main() :
with open('in03.txt') as in_file :
t = int(in_file.readline())
for i in range(1, t + 1) :
n, k, l = get_list(in_file)
turn_list(l)
r = False
b = False
for y in range(0, n) :
for x in range(0, n) :
if 'B' == l[y][x] and not b :
b = find(l, x, y, 'B', k)
elif 'R' == l[y][x] and not r :
r = find(l, x, y, 'R', k)
if r and b :
print('Case #{}: Both'.format(i))
elif r :
print('Case #{}: Red'.format(i))
elif b :
print('Case #{}: Blue'.format(i))
else :
print('Case #{}: Neither'.format(i))
main()
[ 本帖最后由 Maxwell 于 2011-4-3 21:05 编辑 ]
|
|
|