有m个人玩萝卜蹲游戏,每个人说出一个不重复的词汇,组成序列s,大家依次报s里面的单词,每一轮最长有b个单词,如下图所示,
b=5,m=3,s=[‘a’,’b’,’c’],按照下列顺序进行游戏
[‘a’]
[‘a’, ‘b’]
[‘a’, ‘b’, ‘c’]
[‘a’, ‘b’, ‘c’, ‘a’]
[‘a’, ‘b’, ‘c’, ‘a’, ‘b’]
[‘a’, ‘b’, ‘c’, ‘a’]
[‘a’, ‘b’, ‘c’]
[‘a’, ‘b’]
求已经知道某个单词出现的次数,求这是第几轮
想法:求出一个循环该单词出现的最大次数counter,然后n=n%counter,然后计算n出现在第几轮,加上之前的轮数
b=5
n=4000 #出现次数
word=’b’#已知
s=[‘a’,’b’,’c’]
ss=s*b
ss=ss[:b]
ss_max=[]
for i in range(len(ss)):
ss_max+=ss[:i+1]
print(ss[:i+1])
for i in range(len(ss)):
if len(ss[:len(ss)-i-1])>1:
ss_max+=ss[:len(ss)-i-1]
print(ss[:len(ss)-i-1])
counter=0
m=0
for i in ss_max:
if i==word:
counter+=1
if n>counter:
m=int(n/counter)
n=n%counter
lunshu=(2b-1)m
print(m)
for i in range(len(ss)):
lunshu += 1
for j in ss[:i+1]:
if j==word:
n-=1
if n==0:
break
if n==0:
break
if n>0:
for i in range(len(ss)):
if len(ss[:len(ss) - i - 1]) >1:
lunshu += 1
for j in ss[:len(ss) - i - 1]:
if j==word:
n-=1
if n==0:
break
if n==0:
break
print(lunshu)
这是pascal吗(我猜的,反正不是c++()
注意格式哦