gausser
发表于 2017-9-16 08:09:24
people =
count = 0
each = 0
while len(people) > 1:
count += 1
each = each + 1
if each > len(people):
each = each % len(people)
if count % 3 == 0:
out = people.pop(each - 1)
print out
each = each - 1
if each == len(people): each = 0
count = 0
if len(people) == 1:
break
print people
aixuexi82
发表于 2017-9-28 12:58:59
本帖最后由 aixuexi82 于 2017-9-28 13:05 编辑
num = int(input('请输入人数(大于1人):'))
queue = list(range(num))
if num <= 1:
print('输入人数错误!')
while queue:
if len(queue) >= 3:
queue.pop(2)
queue = queue + queue[:2]
elif len(queue) == 2:
print('最后剩下No.%d' % (queue+1))
break
精简掉几行……
z1446773686
发表于 2018-2-24 00:14:24
def Rlist():
list1 = []
import random
number = random.randint(7,16)
for i in range(0,10):
list1.append(i+1)
return list1
def indexon(list2):
count = 1
math = 0
while(len(list2) >= 2):
if count == 3:
print(list2)
count = 0
if len(list2) > 3:
del list2
math -= 1
else:
del list2
if math == len(list2):
math = -1
count += 1
math += 1
print(math)
return list2
count = 1
while(True):
list1 = Rlist()
#print(len(list1))
list2 = indexon(list1)
print(list2)
count += 1
guess = input(' ')
还是有很多的不做之处目前测出9和10个人可以正常执行
纳兰小寒
发表于 2018-2-25 22:48:53
import random
rd = random.randint(20,100)
print('系统随机生成%d人围成一圈' % rd)
l = list(range(1,rd + 1))
a = 0
while(len(l) >= 2):
for i in l:
a += 1
if a == 3:
l.remove(i)
a = 0
print(l)
z1446773686
发表于 2018-2-26 08:53:21
本帖最后由 z1446773686 于 2018-2-26 08:58 编辑
z1446773686 发表于 2018-2-24 00:14
def Rlist():
list1 = []
import random
修改后的:
def Rlist():
list1 = []
import random
number = random.randint(0,10)
print(number)
for i in range(0,number):
list1.append(i+1)
return list1
def indexon(list2):
#math2 = []
#count2 = []
count = 1
math = 0
while(len(list2) > 1):
if math > (len(list2) - 1):
math = 0
if count == 3:
#print('list2:',list2,len(list2))
#print('count2:' , count2,len(count2))
#print('math2:', math2)
count = 0
del list2
math -= 1
#count2.append(count)
count += 1
math += 1
#math2.append(math)
return list2
while(True):
list1 = Rlist()
#print(len(list1))
list2 = indexon(list1)
print('list2:',list2,len(list2))
guess = input(' ')
大头目
发表于 2018-3-7 12:59:02
def cycle_pass(list1,k):
n = 0
while len(list1) > 1:
list2 = list1.copy()
for each in list2:
if each != list2[-1]:
n +=1
if n % k == 0:
print(n,each)
list1.remove(each)
list1.reverse()
print(list1)
return list1
print(cycle_pass(,3))
tsembrace
发表于 2018-4-7 21:03:30
'''
有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子
问最后留下的是原来第几号的那位。
'''
def funcall(n):
lista=
while len(lista)>3:
#每次循环删除第三个元素,并把前两个放到最后
lista=(lista+lista[:2])
return lista
print(funcall(100))
jrro452
发表于 2018-4-29 14:11:21
冬雪雪冬 发表于 2017-3-31 23:21
又仔细看了我自己的程序,发现一个BUG,当num=2时列表下标越界。修改过的:
膜拜大佬····如此简洁·····其中的n=(n+2)%len(list1)怎么理解的啊,小白搞不懂了。
另外我试了1000000个人的时候要7分多钟才出结果,代码这么简洁为啥要那么久啊。
多少人围成一圈:1000000
最后留下的是原来第637798号
0:07:48.181779
BISHIQIUQIUI
发表于 2018-5-10 16:05:17
#有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
n=int(input("排队人数:"))
shuzu=[]
a=0
for i in range(n):
a+=1
shuzu.append(a)
print(shuzu)
#生成n个元素的数组
b=2
while len(shuzu)>1:
shuzu.pop(b)
b=(b+2)%len(shuzu)
print(shuzu)
#倒数第二行的代码不太理解
aaaqqq2004
发表于 2018-6-8 09:27:19
n=1000#多少人围成一圈
nums=list(range(1,n+1))
k=3#报数到3
m=0
num=0#出局多少个
while num<n-1:#只剩下一个时终止循环
num=0
for i in range(0,n):
if nums!=0:
if m+1>=k:#循环报数1,2,3...k
nums=0#报数为k出局,置0
m=0
else:
m=m+1
continue
else:
num=num+1
print ("最后留下的是:",list(filter(None,nums)))
892427369
发表于 2018-7-28 12:34:09
n = int(input('请输入人数:'))
a = list(range(1,n+1))
while len(a)>1:
for x in range(1,3):
a.append(a.pop(0))
a.pop(0)
print('最后留下的是',a,'号位的那位',sep="")
DavidCowboy
发表于 2018-8-6 14:37:04
有理解錯嗎?每三個人踢出一個,多踢個幾輪最後只剩下第1,2號兩個人???
還是要想成,繞圈圈,尾巴會接到頭??
list1 = []
for i in range(1 , 101):
list1.append(i)
while len(list1) >= 1:
temp = len(list1) - (len(list1) // 3)
for n in range(1 , (len(list1) + 1 - temp)):
list1.pop(2*n)
print(list1)
quan-renda
发表于 2018-8-29 18:59:48
n = int(input('请输入1个正整数:'))
lst=[]
for i in range(1,n+1):
lst.append(i)
while lst[-2]!=lst[-1]:
for a, b in enumerate(lst):
if (a+1)%3==0:
pass
else:
lst.append(b)
print("最后留下的是原来第%d号的人:" %(lst[-1]))
d2nte
发表于 2018-9-10 03:14:26
n = int(input("please input n:"))
k = int(input("please input k:"))
people = []
for p in range(1,n+1):
people.append(int(p))
i = 0
while True:
out = []
l = len(people)
if l < 2:
print(people)
break
for c in range(l):
i += 1
if i%k == 0:
out.append(people)
for men in out: people.remove(men)
冷焰溶冰
发表于 2018-9-12 22:57:12
'''
题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
'''
person = int(input("give your person:"))
test_person=
print(test_person)
back_name = *person
cont_number = []
print(back_name)
while len(cont_number) < len(back_name)-1:
for i in range(person):
if back_name == 0:
if test_person % 3 == 0:
back_name = 1
cont_number.append(i)
else:
test_person+=(back_name.count(0)%3)
else:
continue
print(back_name)
print(back_name.index(min(back_name))+1)
pixie0096
发表于 2018-11-30 18:13:14
def c(n):
global man_list
out_list = []
for i in range(n,len(man_list)+n):
if i%3 == 0:
out_list.insert(0,i-n)
if i == len(man_list)+n-1:
global start
start = (i%3)+1
for each in out_list:
del man_list
man_list = ['a','b','c','d','e','f','g']
number = {}
for i in range(1,len(man_list)+1):
number] = i
start = 1
if len(man_list) != 1:
c(start)
while 1:
if len(man_list) != 1:
c(start)
else:
break
print(number])
double-lee
发表于 2018-12-4 23:07:37
[*]def people(num_l,n):
[*] for i in range(1,n+1):
[*] num_l.append(i)
[*] return num_l
[*]def num(num_l,n):
[*] count = 0
[*] j = 0
[*] while n > 1:
[*] for i in range(j,n):
[*] count += 1
[*] if count == 3:
[*] count = 0
[*] print("原始编号 %d 号淘汰!!!"%num_l)
[*] del num_l
[*] if i == n-1:
[*] j = 0
[*] else:
[*] j = i
[*] n -= 1
[*] break
[*] if i == n-1:
[*] j = 0
[*] break
[*] return num_l
[*]num_list = []
[*]n = int(input("请输入游戏人数:"))
[*]people(num_list,n)
[*]num(num_list,n)
[*]print("最后留下的是原来的第 %d 号!"%num_list)
北城以北灬
发表于 2019-3-4 15:40:31
num = int(input("请输入总人数:"))
arr =
print(arr)
rm = 0
lp = 0
ix = 0
while rm < num - 1:
if arr != 0:
lp += 1
if lp == 3:
arr = 0
rm += 1
lp = 0
ix += 1
if ix == num:
ix = 0
print("最后剩下的人是原来的第", arr.index(max(arr))+1, "号。")
lwy520
发表于 2019-3-17 20:46:47
def baoshu(num_rest):
if len(num_rest)<=2:
return num_rest
elif len(num_rest)==3:
num_rest.pop()
return(baoshu(num_rest))
else:
num_rest1=num_rest
num_rest1.extend(num_rest)
return(baoshu(num_rest1))
num=int(input("请输入人数:"))
num_ini=list(range(num))
for i in range(len(num_ini)):
num_ini=num_ini+1
print(num_ini)
num_rest=baoshu(num_ini)
print(num_rest)
lwy520
发表于 2019-3-17 21:00:50
刚才的错了,这个才对
def baoshu(num_rest):
if len(num_rest)==1:
return num_rest
elif len(num_rest)==2:
return num_rest
elif len(num_rest)==3:
num_rest.pop()
return(baoshu(num_rest))
else:
num_rest1=num_rest
num_rest1.extend(num_rest)
return(baoshu(num_rest1))
num=int(input("请输入人数:"))
num_ini=list(range(1,num+1))
print(num_ini)
num_rest=baoshu(num_ini)
print(num_rest)