The problem is from codeforces: http://codeforces.com/contest/263/problem/A
It looks complex but in fact it is not. There is only one ‘1’ element in this fixed-5X5 matrix. The shortest path to the middle cell (2, 2) i.e. the left-top corner is (0, 0) is the absolute difference of x coordinate and y coordinate to (2, 2).
#!/usr/bin/env python for i in xrange(1, 6): s = map(int, raw_input().split()) for k in xrange(1, 6): if s[k - 1] == 1: print abs(i - 3) + abs(k - 3) break
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
161 wordsloading...
Last Post: Multidimensional Array of Lists in Python
Next Post: Codeforces: B. Squares