Python Template For SRM

今天年三十,昨天恰好看到今天早上 10 点有 SRM,于是准备搞一搞。

语言,Python 吧。

于是涉及到如何提高效率的问题:

下面先做了一题 Practice Room 写了一题:

# SRM_605_DIV1_250 class AlienAndHamburgers: def getNumber(self, type, taste): y = set() x = dict() v = list(zip(taste, type)) a = 0 for p in v: if p[0] >= 0: a += p[0] y.add(p[1]) for p in v: if p[0] < 0 and not p[1] in y: x[p[1]] = max(x.get(p[1], p[0]), p[0]) y = len(y) for p in sorted(x.values(), reverse=True): if (y + 1) * (a + p) >= y * a: y += 1 a += p else: break return y * a

cin = ( ((1, 2), (4, 7)), ((1, 1), (-1, -1)), ((1, 2, 3), (7, 4, -1)), ((1, 2, 3, 2, 3, 1, 3, 2, 3, 1, 1, 1), (1, 7, -2, 3, -4, -1, 3, 1, 3, -5, -1, 0)), ((30, 20, 10), (100000, -100000, 100000)), )

cout = ( 22, 0, 30, 54, 400000, )

obj = AlienAndHamburgers()

success = True

for i in range(len(cin)): print('Case #%d:' % i) out = obj.getNumber(*cin[i]) ans = cout[i] if ans == out: print(' Yes! ans = %s' % str(ans)) else: print(' No! ans = %s' % str(ans)) print(' output: %s' % str(out)) success = False

print('\n***************') print(' Accepted!' if success else ' Wrong Answer!') print('***************')

然后修正了一下,得到一个通用的模板,到时直接粘贴签名等重要信息即可得到测试模板:

class %ClassName%: def %MethodName%(self, %*args%): pass

cin = ( # test case input here )

cout = ( # test case output here )

obj = %ClassName%()

success = True

for i in range(len(cin)): print('Case #%d:' % i) out = obj.%MethodName%(*cin[i]) ans = cout[i] if ans == out: print(' Yes! ans = %s' % str(ans)) else: print(' No! ans = %s' % str(ans)) print(' output: %s' % str(out)) success = False

print('\n***************') print(' Accepted!' if success else ' Wrong Answer!') print('***************')

相当简陋,但是已经可以把不少的大脑工作外包了。


【转载请附】愿以此功德,回向 >>

原文链接:http://www.huangwenchao.com.cn/2014/01/srm_py_template.html【Python Template For SRM】

《Python Template For SRM》有1个想法

  1. Pati, I’m waaaaaaaaaaaay older than you and I cried at first! By the next morning I realized how spectacular she really was! Immediately after, I was worried about how she felt, if she knew, silly stuff like that and I was afraid people would make fun of her! Then I realized how that loss elevated her and even the haters realized what a spectacular horse she was!! She is insanely great and I’m so proud to have watched her career!

发表评论

电子邮件地址不会被公开。 必填项已用*标注