double-lee
发表于 2018-12-4 19:54:07
import random as r
# 随机生成n个整数
def createNums(num_l,n):
for i in range(n):
num = r.randint(2,50)
num_l.append(num)
return num_l
# 循环一次后的结果
def circu(num_l):
length = len(num_l)
a = num_l
for i in range(length-1):
num_l += num_l
if num_l > 100:
num_l %= 100
num_l[-1] += a
if num_l[-1] > 100:
num_l[-1] %= 100
return num_l
# 循环k次后的结果
def circulation(num_l,k):
for i in range(k):
circu(num_l)
return num_l
num_list = []
n = int(input("请输入要生成整数的个数(2<=n<=50): "))
k = int(input("请输入要循环的次数(1<=k<=20000000): "))
createNums(num_list,n)
print(num_list)
circulation(num_list,k)
print(num_list)
北城以北灬
发表于 2019-3-4 13:39:41
import random
import time
def make_arr(n):
arr = []
for i in range(n):
arr.append(random.randint(0, 99))
return arr
def magic(n, k):
# arr =
arr = make_arr(n)
print(arr)
for i in range(k):
# print(arr)
temp = arr
for j in range(n - 1):
arr = (arr + arr) % 100
arr = (arr + temp) % 100
return arr
begin = time.time()
arr = magic(50, 20000000)
print(arr)
print(time.time() - begin)
结果为:
99.58436131477356
不知道程序有没有哪里不对
lwy520
发表于 2019-3-16 10:08:35
import random as rd
molihuan=[]
len_num=int(input("请输入一个正整数作为魔力环序列:"))
for i in range(len_num):
molihuan.append(int(rd.uniform(2,50)))
print(molihuan)
for i in range(20000000):
for j in range(len_num-1):
molihuan+=molihuan
if molihuan>100:
molihuan=molihuan%100
molihuan[-1]+=molihuan
if molihuan[-1]>100:
molihuan[-1]=molihuan[-1]%100
if i % 500000 ==0:
print(i)
print(molihuan)
lwy520
发表于 2019-3-16 10:14:31
ooxx7788 发表于 2017-3-26 18:59
其实基本的算法我也弄出来了,但是不能满足2000万次的需求。
各位不妨试试看n=50,k=20000000,能不能算。
我的版本这个程序跑起来是2分半
import random as rd
molihuan=[]
len_num=int(input("请输入一个正整数作为魔力环序列:"))
for i in range(len_num):
molihuan.append(int(rd.uniform(2,50)))
print(molihuan)
for i in range(20000000):
for j in range(len_num-1):
molihuan+=molihuan
if molihuan>100:
molihuan=molihuan%100
molihuan[-1]+=molihuan
if molihuan[-1]>100:
molihuan[-1]=molihuan[-1]%100
if i % 500000 ==0:
print(i)
print(molihuan)
捞鬼
发表于 2019-3-18 21:09:39
jerryxjr1220 发表于 2017-3-26 19:35
题目本身没难度,只是当n=50, k=20000000的时候,运算慢了一些,不过也还行,就几分钟
举例,当n ...
大哥,我想问一下你代码中的self.rings+=self.ring不是会有溢出的可能吗,但问什么代码不会报错呢?
yu123py
发表于 2019-4-27 21:06:46
速度很慢
import random
l =
k = int(input('请输入循环次数:'))
print(l)
for i in range(k):
temp = l
for j in range(len(l)):
if j == len(l) - 1:
l = l + temp
else:
l = l + l
if l >= 100:
l = l % 100
print(l)
panheng
发表于 2019-8-11 23:43:58
交作业!
n = int(input("请输入手环数字n(2-50之间):"))
k = int(input("循环次数k(1-20000000之间):"))
str1 = input('请输入{}个0-9的整数(以逗号“,”分隔)'.format(n))
list1 = #将输入n个数转化为列表
count = 0 #计数器初始化
print("第{}次变化后的数列{}".format(count, list1)) #打印初始值
while count < k:
for i in range(n):
if count == k: #增加断点检测,防止计数器超出设定
break
else:
count += 1
if i < n-1: #第1到n-1个数字变换
if list1 + list1 <= 100: #超过100取模
list1 += list1
else:
list1 = (list1 + list1) % 100
print("第{}次变化后的数列{},正在变换第{}个数".format(count, list1,i+1))
else:
if list1 + list1 <= 100: #第n个数字变换
list1 += list1
else:
list1 = (list1 + list1) % 100
print("第{}次变化后的数列{},正在变换第{}个数".format(count, list1,i+1))
print("变换第{}次的数值为:{}".format(k, list1))
克里斯保罗
发表于 2019-8-25 20:16:05
~~import datetime as dt
class Band:
def __init__(self,n,k):
self.n = n
self.dic={}
fori in range(1,n+1):
self.dic = i
t = k-1
while t:
self.newdic()
t -=1
self.last_dic = self.newdic()
last_list = []
for a in self.last_dic:
last_list.append(str(self.last_dic))
print(last_list)
def newdic(self):
dic1 = {}
for i in self.dic:
dic1 = self.dic
for a in self.dic:
if a == len(self.dic):
self.dic = dic1 + dic1
else:
self.dic = dic1 + dic1
if self.dic >= 100:
self.dic = self.dic%100
return self.dic
def main():
t1 = dt.datetime.now()
n = int(input('请输入n的个数:'))
k = int(input('请输入循环次数:'))
exp = Band(n,k)
t2 = dt.datetime.now()
temp = t2 - t1
print(temp)
if __name__ == '__main__':
main()
暮让
发表于 2019-9-25 22:46:48
本帖最后由 暮让 于 2019-9-25 22:49 编辑
import datetime
import random
n, k = input("请输入n 和 k:").split(' ')
n, k = int(n), int(k)
temp = int(input("请选择导入数据方式:\n1.系统随机\n2.手动输入\n请选择:"))
list1 = []
if temp == 1:
for i in range(n):
list1.append(random.randint(0, 99))
elif temp == 2:
array = input("请输入%d个数字:" % n).split(' ')
for i in array:
list1.append(int(i))
print("您导入的数据为:", list1)
t1 = datetime.datetime.now()
for _ in range(k):
a = list1
for i in range(n):
if list1 > 100:
list1 %= 100
if i == len(list1) - 1:
list1 += a
if list1 > 100:
list1 %= 100
break
list1 += list1
t2 = datetime.datetime.now()
print(list1)
print(t2-t1)
Jung
发表于 2019-11-26 08:52:20
import time
def fun13():
Tstart = time.time()
Lnew = []
L =
Counttimes = int(input("please enter the number you want to count:"))
for i in range(Counttimes):
for j in range(len(L)):
if(j==(len(L)-1)):
Lnew.append(Lnew)
else:
Lnew.append(L+L)
if(Lnew>100):
Lnew = Lnew%100
L = []
L = Lnew
Lnew = []
print(L,(time.time()-Tstart),i) #每次显示结果,时间,次数。2百万次大概需要750s.在shell下运行要慢很多。
小白Alvin
发表于 2020-2-12 10:10:24
n = int(input("请输入魔力手环有几个数字构成:"))
A =
def status(k):
# 转了多少圈
cir = k//n + 1
# B = []
# # 生成的新列表
# for i in range(cir):
# B += A
for i in range(k):
# 转一次的状态
# 用B来记录新的状态中的各数字
B = []
for j in range(len(A)):
if j == 0:
B.append((A+A[-1])%100)
else:
B.append((A+A)%100)
# 更新A,将A中的元素变为转换之后的元素
for m in range(len(B)):
A = B
return A
xuanyuan0116
发表于 2020-2-23 17:14:00
print('----------每日练习题13----------')
#一个由n个数字构成的环,每次变化后,每个数字会变成自己和后面一个数的和,最后一个数的后面是第一个数。
#当数字大于100时,取模。
#给出这个手环开始的n个数字,循环次数k,循环后的数值。
#要求 2<=n<=50, 1<=k<=20000000;
#注意,一定使得运算可以满足以上n,k的要求(所以,不要认为一个小数字你可以算出来,大数字就一定能算的出来,尽量让计算在有限的时间内完成)。
import random as rd
import time as t
start = t.process_time()
n = int(input('Please input n:'))
k = int(input('Please input k:'))
list1 = []
for i in range(n):
list1.append(rd.randint(0,99))
print(list1)
count = 0
while count != k:
list2 = []
for i in range(len(list1)-1):
if list1 + list1 >= 100:
list2.append((list1 + list1) % 100)
else:
list2.append(list1 + list1)
list2.append(list1)
list1 = []
list1 = list2
#print(list2)
count += 1
print(list2)
end = t.process_time()
t = end - start
print('Runtime is %f s:'%t)
----------每日练习题13----------
Please input n:50
Please input k:20000000
Runtime is 831.984375 s:
用时10分多钟
杜若左
发表于 2020-3-8 17:09:26
{:10_256:}a = []
n = int(input("你想让这个环有几个数字呢?"))
for i in range(0,n):
k = int(input("请输入第"+str(i+1)+"个数字(输入的数字应该小于100)"))
a.append(k)
k = int(input("你想让这个环循环几次呢?"))
for t in range(0,k):
for i in range(0,n-1):
if i==0:
j = (a)%100
a = (a + a)%100
a = (a + j)%100
print(a)
print("运算完成!")
素手就琴
发表于 2020-6-7 12:27:49
n = int(input("请输入一个从2到50范围的整数:"))
k = int(input("请输入一个从1到2000000000范围的整数:"))
temp = input("请输入n个数,n是您输入的第一个整数,数之间用空格隔开:")
magic_list = temp.split()
for i in range(n):
magic_list = int(magic_list)
i = 1
j = 0
while i <= k:
p = magic_list
while j < n-1:
magic_list = magic_list + magic_list
if magic_list >= 100:
magic_list %= 100
j += 1
else:
magic_list = magic_list + p
if magic_list >= 100:
magic_list %= 100
p = magic_list
i += 1
j = 0
print(magic_list)
sanchuan555
发表于 2020-12-13 21:15:35
import random as r
cycle1=[]
times1=0
for num in range(r.randint(2, 50)):
times1+=1
cycle1.append(r.randint(0, 99))
print(cycle1)
K=r.randint(1,20000000)
print(K)
while K>0:
location1=0
cycle2=[]
for num_2 in cycle1:
if location1+1==len(cycle1):
num_2=num_2+cycle1
else:
num_2=num_2+cycle1
location1+=1
cycle2.append(num_2)
K-=1
print(cycle2)
满不懂
发表于 2020-12-13 22:15:59
新人报到进来看看
逃兵
发表于 2021-1-30 13:59:43
num =
num =
n = int(input())
def jisuan(num,n):
for i in range(n):
temp = num
for i in range(len(num)):
try:
num+=num
if num > 100:
num =num - 100
except:
num+=temp
if num > 100:
num =num - 100
return num
print(jisuan(num,n))