konchin_shih

0818 09:00

Aug 17th, 2021
1,049
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1.  
  2. table = [
  3.     [1, 2, 3, 4, 3],
  4.     [2, 4, 3, 7, 5],
  5.     [4, 3, 3, 3, 2],
  6.     [7, 4, 0, 4, 2],
  7.     [1, 5, 3, 0, 9]
  8. ]
  9.  
  10. d = [(1, 0), (0, 1), (1, 1), (-1, 0), (0, -1), (-1, -1), (1, -1), (-1, 1), (0, 0)]
  11.  
  12.  
  13. def check(x, y, lx, ly):
  14.     return x < 0 or y < 0 or x >= lx or x >= ly
  15.  
  16.  
  17. def f(s, x, y, lx, ly):
  18.     maxp = (x, y)
  19.     maxn = table[x][y] * s
  20.     for dx, dy in d:
  21.         cur = 0
  22.         if check(x + s * dx, y * s * dy, lx, ly):
  23.             continue
  24.         for k in range(1, s + 1):
  25.             cur += table[x + k * dx][y + k * dy]
  26.         if maxn < cur:
  27.             maxn = cur
  28.             maxp = (x + s * dx, y * s * dy)
  29.     return (maxn, maxp)
  30.  
  31.  
  32. print(f(2, 2, 2, 5, 5))
  33.  
Advertisement
Add Comment
Please, Sign In to add comment