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'
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'
相关文章推荐
- Review of Codeforces 6B and 6C
- Review of Codeforces 5C. Longest Regular Bracket Sequence
- Review of codeforces 492C Vanya and Computer Game based on Python
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- codeforces Minimum number of steps (804 B)
- Educational Codeforces Round 4 D. The Union of k-Segments 排序,思维
- Educational Codeforces Round 11 D. Number of Parallelograms
- Codeforces Round #399 E Game of Stones 博弈
- Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers
- codeforces gym 2016-2017 NEERC, Moscow Subregional K. Knights of the Old Republic 最小生成树+dp
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- 【尺取或dp】codeforces C. An impassioned circulation of affection
- Codeforces Round #399 E Game of Stones 博弈
- codeforces Looksery Cup 2015 C. The Game Of Parity
- Codeforces Round #352 ——Ultimate Weirdness of an Array
- Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers
- Codeforces Round #277.5 (Div. 2) C. Given Length and Sum of Digits...
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
- Codeforces Round #277.5 (Div. 2) D. Unbearable Controversy of Being
- Educational Codeforces Round 4 D The Union of k-Segments (扫描线)