您的位置:首页 > 编程语言 > Python开发

Review of codeforces 493B Vasya and Wrestling based on Python

2014-12-04 12:48 806 查看
This task is relatively easy. However, we should notice that the concept of lexicographically larger
is hard to comprehend. 

So, what is lexicographically
larger.


为了便于理解,用中文进行解释,所谓[b]lexicographically
larger,翻译成中文是“字典序”。这个就比较好理解了。就像查字典按字母顺序从左到右一样排列比较。比如 car > cat    apple > cat    12345 > 12354类似的。
[/b]

So, it will be easy if we know the concept of lexicographically
larger.
We can first append positive numbers and negative numbers into two arrays. Then reverse each array. pop elements in each array one by one and compare them. 

Source code can be found as follows:

n = input()
a = []
x = [0]
y = [0]
d = 0
for i in xrange(n):
temp = int(raw_input())
a.append(temp)
if temp > 0:
x.append(temp)
else :
y.append(-temp)
s = sum(a)
x.reverse()
y.reverse()
if s > 0:
print 'first'
elif s < 0:
print 'second'
else :
while True:
d = x.pop() - y.pop()
if d != 0 or len(x)== 0 or len(y)==0:
break
if d > 0:
print 'first'
elif d < 0 :
print 'second'
else :
if a[-1] > 0:
print 'first'
else :
print 'second'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: