SRM 595 DIV 1

逻辑分析题,注意以下关键性质:

一个球被染成什么颜色取决于最后一次的染色情况,如果没有被染过色,那么默认是白色

结果总是的2的乘方

 1 class LittleElephantAndIntervalsDiv1:
 2     def getNumber(self, m, l, r):
 3         # the last color
 4         a = [-1] * m
 5         for rou in range(0, len(l)):
 6             for i in range(l[rou]-1, r[rou]):
 7                 a[i] = rou
 8                 
 9         # count key round
10         s = set(a)
11         
12         # calc
13         tot = 2 ** (len(s) - (1 if -1 in s else 0))
14         return tot
15     
16     
17     
18 # test 
19 o = LittleElephantAndIntervalsDiv1()
20 
21 # test case
22 assert(o.getNumber(4, (1,2,3), (1,2,3)) == 8)
23 assert(o.getNumber(3, (1,1,2), (3,1,3)) == 4)
24 print('ok')
View Code
原文地址:https://www.cnblogs.com/valaxy/p/3402670.html