Codeforces: A. Beautiful Matrix


The problem is from codeforces: http://codeforces.com/contest/263/problem/A

263A Codeforces: A. Beautiful Matrix beginner brute force codeforces implementation programming languages python string tricks

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 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 words
Last Post: Multidimensional Array of Lists in Python
Next Post: Codeforces: B. Squares

The Permanent URL is: Codeforces: A. Beautiful Matrix

Leave a Reply