CF 443A

print len(set(raw_input() + ', ')) - 4

CF 133A

print "YNEOS"[not set('HQ9')&set(raw_input())::2]

CF 146A

n, t = input(), raw_input()
print ['NO', 'YES'][set(t) <= set('47') and sorted(t[:n/2] * 2) == sorted(t)] # 直接排序比统计47更简洁

最近的一场:
CF #253 (Div. 1) A

import itertools
n, cards = input(), map(set, set(raw_input().split()))
for sz in range(11):
  for hints in map(set, itertools.combinations('RGBYW12345', sz)):
    if len(cards) == len(set(map(tuple, (hints & x for x in cards)))):
      print sz
      exit()

附一个列表解析:
CF 66A

n = input()
print [type for type, x in(('byte', 7), ('short', 15), ('int', 31), ('long', 63), ('BigInteger', 1000)) if 2 ** x > n][0]

巧妙地结合reducelambda
CF 462A

n = input()
b = ['x'*(n+2)]
b += ['x'+raw_input()+'x' for i in range(n)]
b += ['x'*(n+2)]
print 'NO' if any(reduce(lambda x, y : x ^ y, (b[x/n+1+i][x%n+1+j] == 'o' for (i, j) in zip((1,0,-1,0), (0,1,0,-1)))) for x in range(n*n)) else 'YES'

持续更新。。

Comments

comments powered by Disqus