Algorithms, Blockchain and Cloud

Codeforces: A. System Administrator


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

A really simple math problem, can be solved within a few lines of Python code:

#!/usr/bin/env python

ax = asum = 0
bx = bsum = 0

for i in xrange(int(raw_input())):
    t, x, y = map(int, raw_input().split())
    if t == 1:
        ax += x
        asum += 10
    else:
        bx += x
        bsum += 10

print "LIVE" if ax + ax >= asum else "DEAD"
print "LIVE" if bx + bx >= bsum else "DEAD"

Many others are shorter.

a=[0,0]
for i in 'i'*input():t,x,y=map(int,raw_input().split());a[t>1]+=x-y
for i in a:print "LDIEVAED"[i<0::2]

Or

print "\n".join([["DEAD","LIVE"][a>=b] for t in zip(*[(x[a!=1],x[a==1]) for i in xrange(int(raw_input())) for (a,b,c) in [map(int,raw_input().split())] for x in [((b,c),(0,0))] ]) for (a,b) in [map(sum,zip(*t))] ])

Or

def f(i, b):
	return ['DEAD', 'LIVE'][sum(x - y for t, x, y in b if t == i) >= 0]

n = input()
b = [map(int, raw_input().split()) for _ in range(n)]
print f(1, b)
print f(2, b)

Or

c=[0+0j]*2
for _ in range(input()):
  x,y,z=map(int,raw_input().split())
  c[x-1]+=complex(y,z)
for x in c:
  print 'DEAD' if x.real*2 < x.real+x.imag else 'LIVE'

The last method is quite interesting because it uses complex number to solve this problem.

–EOF (The Ultimate Computing & Technology Blog) —

326 words
Last Post: Quick Demonstration of Quick Sort in Python
Next Post: GCD, Greatest Common Divisor

The Permanent URL is: Codeforces: A. System Administrator (AMP Version)

Exit mobile version