Advertisement
K_Y_M_bl_C

Untitled

May 1st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. import math
  2.  
  3. f1 = open('input.txt')
  4. f2 = open('output.txt', 'w')
  5.  
  6. n, m = map(int, f1.readline().split())
  7. x, y = map(int, f1.readline().split())
  8. colour = int(f1.readline())
  9.  
  10. a = []
  11.  
  12. for i in range (n):
  13.     a.append([])
  14.     a[i] = list(map(int, f1.readline().split()))
  15.  
  16. if (a[x][y] == colour):
  17.     f2.write(str(0) + '\n')
  18.     for x in a:
  19.         for y in x:
  20.             f2.write(str(y) + ' ')
  21.         f2.write('\n')
  22.  
  23. q = []
  24. was = []
  25. dx = [0, 1, 0, -1]
  26. dy = [-1, 0, 1, 0]
  27.  
  28. q.append((x, y))
  29.  
  30. while (len(q)):
  31.     p = q.pop(0)
  32.     x = p[0]
  33.     y = p[1]
  34.     was[x][y] = 1
  35.     for i in range(4):
  36.         if not(was[x + dx[i]][y + dy[i]]):
  37.             if (a[x + dx[i]][y + dy[i]] ==)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement