Codeforces: A. Young Physicist


The problem is from codeforces: http://www.codeforces.com/problemset/problem/69/A

69A Codeforces: A. Young Physicist beginner codeforces implementation math non-technical python

The tests were not strong because I failed at the 81-th test on the first submission using a wrong algorithm (actually I mis-understood the problem statement and gave a wrong algorithm at the beginning). I added all numbers and check if it is zero. However, you need to check each coordinate separately. It is superising to see that the first 80 tests satistfy that sum of all numbers is zero and for each coordinate is zero as well.

The python solution is as follows.

n = int(raw_input())

sx = 0
sy = 0
sz = 0

for i in range(0, n):
    ss = raw_input().split(" ")
    sx += int(ss[0])
    sy += int(ss[1])
    sz += int(ss[2])

print "YES" if sx == 0 and sy == 0 and sz == 0 else "NO"

Here we write the if statement a bit different, instead of writing,

if A:
    print "A"
else:
    print "B"

we can rearrange the order and make it simpler

print "A" if A else "B"

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
244 words
Last Post: Which.bat for windows command shell
Next Post: Codeforces: A. Rock-Paper-Scissors

The Permanent URL is: Codeforces: A. Young Physicist

Leave a Reply