SRM 639 Div2 250 ElectronicPetEasy
問題文
https://apps.topcoder.com/wiki/display/tc/SRM+639
書いた
class ElectronicPetEasy: def isDifficult(self, st1, p1, t1, st2, p2, t2): first = [] for i in xrange(t1): first.append(st1+(p1*i)) second = [] for i in xrange(t2): second.append(st2+(p2*i)) res = "Easy" for i in first: if i in second: res = "Difficult" break return res
他の参加者のコードみた
class ElectronicPetEasy: def isDifficult(self, st1, p1, t1, st2, p2, t2): feed1 = set(range(st1, st1+p1*t1,p1)) feed2 = set(range(st2, st2+p2*t2,p2)) if feed1 & feed2 == set([]): return "Easy" return "Difficult"
感想
rangeでstart, stop, stepを指定すると等差数列を作れる。 set形だと&で共通する要素があるか比較できるので便利。