-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
65 lines (31 loc) · 1.13 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
n,m,c=map(int,input().split())
#构建一个颜色和珠子位置字典,键为颜色,值为颜色出现的位置列表(按递增顺序排列)
color_index={}
for i in range(0,n):
color=list(map(int,input().split()))
if(color[0]==0):
continue
for c in color[1:]:
color_index.setdefault(c,[]).append(i)
print(color_index)
def gap(a,b,n):
#函数:算两个珠子之间的距离(涉及环)
#n:整串珠子的总数
if(a<=b):
return b-a
else:
return n+b-a
count=0
#遍历字典中出现的每一种颜色
for cl in color_index.keys():
gap_l=[]#记录某种颜色的 珠子相邻珠子位置差
for j in range(0,len(color_index[cl])):
#前面的和自己的下一个位置比,最后一颗和第一颗比
if(j<len(color_index[cl])-1):
gap_l.append(gap(color_index[cl][j],color_index[cl][j+1],n))
else:
gap_l.append(gap(color_index[cl][j],color_index[cl][0],n))
print(gap_l)
if(min(gap_l)<=m):#只要珠子相邻位置差值小于m,那么这个颜色就不合格了
count+=1
print(count)