elbert
发表于 2017-9-23 15:12:07
import time , random
m = int(input("Input cycle times:"))
list1=[]
for i in range(50):
list1.append(random.randint(1,100))
start = time.time()
def change(list1):
n = len(list1)
list2 = []
for i in range(n-1):
list2.append(int(list1) + int(list1))
list2.append(int(list1[-1]) + int(list1))
for j in range(n):
if list2 >=100:
list2 = list2%100
list1 = list2
return (list1)
for k in range(m):
list1 = change(list1)
print(list1)
end = time.time()
print(end-start)
aixuexi82
发表于 2017-9-28 12:36:04
本帖最后由 aixuexi82 于 2017-9-28 12:38 编辑
我的垃圾码,最大值跑了好久{:5_100:}
n = int(input('请输入构成魔力环的数字个数(2-50之间):'))
k = int(input('请输入需要循环的次数(1-20000000之间):'))
temp = str(input('请输入魔力环中的数字,以空格隔开:'))
mylist = temp.split(' ')
mylist = list(map(eval,mylist))
result = 1
if len(mylist) != n:
print('输入个数不匹配!')
result = 0
else:
for times in range(k):
first = mylist
for i in range(n-1):
mylist += mylist
mylist = mylist + first
for j in range(n):
if mylist >= 100:
mylist -= 100
if result:
print(mylist)
请输入构成魔力环的数字个数(2-50之间):50
请输入需要循环的次数(1-20000000之间):20000000
请输入魔力环中的数字,以空格隔开:1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
yjsx86
发表于 2018-1-19 07:56:09
本帖最后由 yjsx86 于 2018-1-19 07:58 编辑
开始 50 数 循环 20000000 次
代码运行 耗时 3.78 分钟 验证过代码 没问题
import random
from functools import reduce
def func(x, y):
_sum = x + y
if _sum > 100:
_sum = _sum % 100
temp.append(_sum)
return y
MagicRing = random.choices(,k=50)
for x in range(20000000):
temp = []
MagicRing.append(MagicRing)
reduce(func, MagicRing)
MagicRing = temp
print(MagicRing)
# 结果
Finnished in 229.32459 sec
瞬秒爆加速
发表于 2018-3-6 14:16:19
def ml(l,n,k):
K = 0
while k>=K:
l=(l+l[-1])%100
for i in range(n-1):
l = (l+l)%100
else:
l[-1]=(l[-1]+l)%100
K+=1
return l
a= input("n,k= ").split(" ")
n,k =int(a),int(a)
l = input("m= ").split(" ")
if n==len(l):
for i in range(len(l)):
l = int(l)
else:print("error")
if __name__=="__main__":
print(ml(l,n,k))
大头目
发表于 2018-3-6 19:49:22
def cycle_add(listn,k):
while k:
list1 = listn.copy()
for i in list1:
buf = list1.index(i)
if i != list1[-1]:
listn = listn + listn
else:
listn = listn + list1
if abs(listn) >= 100:
listn = listn % 100
k -= 1
return listn
print(cycle_add(,101))
benzhj
发表于 2018-3-9 09:58:35
import random
import time
l = []
for i in range(50):
l.append(random.randint(1, 100))
print(l)
timestar = time.clock()
for i in range (20000000):
x = 0
for i in range(50):
x += 1
if x == 50:
l += l
else:
l += l
if l >100:
l = l - 100
timeend = time.clock()
print(l)
print ("time is :{}".format(timeend-timestar))
次数少还可以,200万次,根本跑不出来.....
凌九霄
发表于 2018-3-29 16:31:51
本帖最后由 凌九霄 于 2018-3-29 16:34 编辑
import time,random
n = 50
listone = random.sample(,n)
listtwo = []
newlist = []
listtwo = listone[:]
listtwo.append(listone)
listtwo.pop(0)
print("初始列表(n={0}):".format(n))
print(listone)
start = time.time()
for k in range(1, 20000001):
newlist = [(x + y) % 100 for x, y in zip(listone, listtwo)]
listone = newlist[:]
listtwo = newlist[:]
listtwo.append(listtwo)
listtwo.pop(0)
print("\n最终列表(k={0}):".format(k))
print(listone)
end = time.time()
print("\n总计用时:{0:.2f}s".format(end - start))
z1446773686
发表于 2018-4-7 10:23:19
def random_circulation():
import random
forn_time = random.randint(6,50)
fork_time = random.randint(2,2E7)
list_member = []
for each in range(0,fork_time):
each_member = random.randint(0,101)
list_member.append(each_member)
while(fork_time > 0):
for each_index in (0,len(list_member)-3):
list_member = list_member + \
list_member
if list_member > 100:
list_member %= 100
list_member = list_member + \
list_member
if list_member > 100:
list_member %= 100
fork_time -= 1
return list_member
while(True):
print(random_circulation())
stop = input('\n按下任意键继续循环。\n')
z1446773686
发表于 2018-4-7 11:12:12
z1446773686 发表于 2018-4-7 10:23
def random_circulation():
import random
def random_circulation():
import random
forn_time = random.randint(2,50)
fork_time = random.randint(2,2E7)
list_member = []
for each in range(0,forn_time):
each_member = random.randint(2,101)
list_member.append(each_member)
print(len(list_member),fork_time)
while(fork_time > 0):
for each_index in (0,len(list_member)-3):
list_member = list_member + \
list_member
if list_member > 100:
list_member %= 100
list_member = list_member + \
list_member
if list_member > 100:
list_member %= 100
fork_time -= 1
return list_member
while(True):
print(random_circulation())
stop = input('\n按下任意键继续循环。\n')
tsembrace
发表于 2018-4-7 18:41:54
'''
一个由n个数字构成的环,每次变化后,每个数字会变成自己和后面一个数的和
最后一个数的后面是第一个数。
当数字大于100时,取模。
给出这个手环开始的n个数字,循环次数k,循环后的数值。
要求 2<=n<=50, 1<=k<=20000000;
注意,一定使得运算可以满足以上n,k的要求
(所以,不要认为一个小数字你可以算出来,大数字就一定能算的出来,尽量让计算在有限的时间内完成)。
'''
import time
import random
def gameX(n,k):
#初始化n个数字的环(列表)
listx=[]
for i in range(n):
listx.append(random.randint(1,100))
#创建一个相应移位的环(列表)
listy=listx+]
print("初始列表为:"+str(listx))
print("跟随列表为:"+str(listy))
for i in range(k):
for j in range(len(listx)):
listx=listx+listy
if listx>=100:
listx=listx%100
listy=listx+]
return listx
if __name__=='__main__':
n=int(input("输入数字的数量(n):\n"))
k=int(input("输入要循环的次数(k):\n"))
start=time.time()
print(gameX(n,k))
end=time.time()
print("程序运行了%d秒。" %(end-start))
输入数字的数量(n):
50
输入要循环的次数(k):
20000000
初始列表为:
跟随列表为:
程序运行了259秒。
jrro452
发表于 2018-4-28 16:27:00
凌九霄 发表于 2018-3-29 16:31
listone = newlist[:]
listtwo = newlist[:]
listtwo.append(listtwo)
listtwo.pop(0)
这里感觉不对呢··但试了最终结果又是对的···
比如初始列表是,append之后的listtwo就是 ,按规则,第一次循环后的结果应该是,但按你的来就是``顺序不对啊···求解释。
jrro452
发表于 2018-4-28 16:33:25
import datetime
print("手环的数字个数n范围:2<=n<=50,循环次数k范围:1<=k<=20000000")
CountNums = input('请输入手环的数字个数n和循环次数k,空格隔开:').split()
print('构成初始手环数字的要求:0到99')
Nums = input('请输入构成手环的每数字,空格隔开:').split()
def strToint(x):
for i in range(len(x)):
x=int(x)
return x
CountNums = strToint(CountNums)
Nums =strToint(Nums)
n = CountNums
k = CountNums
if n!=len(Nums):
print('初始手环个数为%d,输入个数为%d'%(n,len(Nums)))
exit()
def loopCase(lists,x):
for a in range(1,x+1):
slist=lists[:]
for b in range(len(lists)):
if b ==0:
lists=(slist+slist[-1])%100
else:
lists=(slist+slist)%100
return lists
start = datetime.datetime.now()
flist = loopCase(Nums,k)
end = datetime.datetime.now()
print(flist)
print(end-start)
结果:
手环的数字个数n范围:2<=n<=50,循环次数k范围:1<=k<=20000000
请输入手环的数字个数n和循环次数k,空格隔开:50 20000000
构成初始手环数字的要求:0到99
请输入构成手环的每数字,空格隔开: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
0:02:48.658647
小庆子
发表于 2018-4-29 22:29:52
本帖最后由 小庆子 于 2018-4-29 22:31 编辑
numb = list(int(i) for i in(input('请输入一组数字(用空格隔开):').split(' ')))
n = len(numb)-1
k = int(input('你想循环的次数:'))
def M_Ring(n,k,numb):
while k > 0:
temp = numb
for i in range(0,n+1):
if i != n:
numb = numb+numb
if numb >100:
numb = numb -100
else:
numb = numb[-1] + temp
if numb >100:
numb = numb -100
k -= 1
M_Ring(n,k,numb)
print(numb)
跑2000 0000 太久了- -唉
凌九霄
发表于 2018-5-1 09:07:59
jrro452 发表于 2018-4-28 16:27
listone = newlist[:]
listtwo = newlist[:]
listtwo.append(listtwo)
按照题目的意思,一个由n个数字构成的环,每次变化后,每个数字会变成自己和后面一个数的和,最后一个数的后面是第一个数。
如果你的初始列表是,第一轮后就应该是,没毛病啊
jrro452
发表于 2018-5-2 14:49:17
凌九霄 发表于 2018-5-1 09:07
按照题目的意思,一个由n个数字构成的环,每次变化后,每个数字会变成自己和后面一个数的和,最后一个数 ...
你是对的,我没考虑到‘最后一个数的后面是第一个数’这个条件。{:10_277:}
萧丹夜
发表于 2018-5-9 14:29:47
n,k = map(int,input('请输入数字个数n(2<=n<=50)和迭代次数k(1<=k<=2000000000)(以空格隔开):').split(' '))
b = list(map(int,input('请输入魔力手环初始数(以空格分隔):').split(' ')))
for i in range(0,k):
for j in range(0,n):
if j < (n-1):
b = (b + b) % 100
else:
b = (b + b) % 100
print('经过%d次使用后手环状态为:'%k,b)
hfg
发表于 2018-5-30 10:23:26
import random
x = 0
n = int(input('请输入手环的数字个数:'))
k = int(input('请输入循环次数:'))
j = range(0,99)
temp= random.sample(j ,n)
print('初始数组为:'+ str(temp))
a = len(temp)
temp1 = []
number = 1
while number <= k:
for i in range(0,int(a)):
x = temp + temp
if x > 100:
x = x%100
temp1.append(x)
temp = temp1[:]
temp1 = []
print('第%d次循环的数组为:'% number + str(temp))
number += 1
时间运行慢的惨不忍睹。
acgods
发表于 2018-8-24 14:30:04
import random
list1 = []
# n,k = map(int,input("请输入魔力手环显示的数字个数和小易使用魔力的次数:").split(','))
n,k = 50,2000000000
print(n,k)
for i in range(n):
list1.append(random.randint(0,99))
print("魔力手环初始数字为:",list1)
list2 = list1[:]
for j in range(k):
for i in range(n):
if i+1 == n:
list2 = list1 + list1
else:
list2 = list1 + list1
if list2 >= 100:
list2 %= 100
print("魔力手环第%d次使用后显示的数字为:%s" % (j+1,str(list2)),end="\n")
list1 = list2[:]
quan-renda
发表于 2018-8-26 18:08:19
import random as r
str_in = input('用逗号分隔2个正整数:')
lst =
n=lst
k=lst
lst=[]
for i in range(n):
lst.append(r.randint(0,99))
for k in range(k):
for i in range(n-1):
lst+=lst
if lst>100:
lst=lst%100
lst[-1]+=lst
if lst[-1]>100:
lst[-1]=lst%100
print(lst)
pixie0096
发表于 2018-11-30 17:12:02
list1 =
k = 5
l = len(list1)
while k:
for i in range(l):
if i == l-1:
list1 += list1
else:
list1 += list1
if list1 >= 100:
list1 %= 100
k -= 1
print(list1)