TJBEST
发表于 2020-3-18 14:59:05
稍微再等等,五点能提交新方案,暴力的已发。
eachill
发表于 2020-3-18 15:57:17
def n354(left:int, right:int):
temp = []
result = []
for i in range(left, right+1):
f = set(str(i))
if i != 0 and '0' not in f:
for j in f:
if i % int(j) != 0:
temp.append(0)
else:
temp.append(1)
set1 = set(temp)
temp.clear()
if len(set1) == 1 and 1 in set1:
result.append(i)
return result
print(n354(1,10000))
flamezyy
发表于 2020-3-18 16:18:14
def f354(left, right):
list_num = []
for num in range(left, right+1):
str_num = str(num)
if '0' not in str_num:
for i in str_num:
if num % int(i):
break
else:
continue
else:
list_num.append(num)
else:
continue
else:
print(list_num)
ggzgs
发表于 2020-3-18 18:03:20
def q354(left,right):
result = []
for each in range(left,right+1):
a, b= each%10, each
whileb:
if not a:
break
elif each%a:
break
else:
b //= 10
a = b%10
else:
result.append(each)
return result
TJBEST
发表于 2020-3-18 18:42:53
这个比暴力破解时间的40%左右 速度有点进步,但是代码超机长。累死我了{:5_104:}
def fun354(left,right):
def num2digital(num):
result = []
while num:
result.append(num%10)
num = num // 10
result.reverse()
return result
def digital2num(arr):
result = 0
for each in arr:
result = result * 10 + each
return result
def GongBei(iterobj):
result = 1
for each in iterobj:
result = result*each//Gongyue(result,each)
return result
def Gongyue(a,b):
if a<b:
a,b = b,a
while b:
a,b = b,a%b
return a
def Ji():
if m != M:
if dic['bits']<M and dic['bits']>m:
if dic['index'] < dic['bits'] - 1:
Deal(1,10,2,Ji)
else:
Deal(1,10,2,Ji,True)
elif dic['bits'] == M:
if temp == right_arr]:
standard = right_arr]
if dic['index'] < dic['bits'] - 1:
Deal(1,standard+1,2,Ji)
else:
Deal(1,standard+1,2,Ji,True)
else:
if dic['index'] < dic['bits'] - 1:
Deal(1,10,2,Ji)
else:
Deal(1,10,2,Ji,True)
else:
if temp == left_arr]:
standard = left_arr]
if dic['index'] < dic['bits'] - 1:
Deal(9,max(),-2,Ji)
else:
Deal(9,max(),-2,Ji,True)
else:
if dic['index'] < dic['bits'] - 1:
Deal(1,10,2,Ji)
else:
Deal(1,10,2,Ji,True)
else:
if right_arr] == left_arr]:
s1 = left_arr]
s2 = right_arr]
if dic['index'] < dic['bits'] - 1:
Deal((s1//2)*2+1,s2+1,2,Ji)
else:
Deal((s1//2)*2+1,s2+1,2,Ji,True)
else:
if temp < right_arr] and temp > left_arr]:
if dic['index'] < dic['bits'] - 1:
Deal(1,10,2,Ji)
else:
Deal(1,10,2,Ji,True)
elif temp == right_arr]:
standard = right_arr]
if dic['index'] < dic['bits'] - 1:
Deal(1,standard+1,2,Ji)
else:
Deal(1,standard+1,2,Ji,True)
else:
standard = left_arr]
if dic['index'] < dic['bits'] - 1:
Deal(9,max(),-2,Ji)
else:
Deal(9,max(),-2,Ji,True)
def Ou():
if m != M:
if dic['bits']<M and dic['bits']>m:
if dic['index'] < dic['bits'] - 1:
Deal(1,10,1,Ou)
else:
Deal(2,10,2,Ou,True)
elif dic['bits'] == M:
if temp == right_arr]:
standard = right_arr]
if dic['index'] < dic['bits'] - 1:
Deal(1,standard+1,1,Ou)
else:
Deal(2,standard+1,2,Ou,True)
else:
if dic['index'] < dic['bits'] - 1:
Deal(1,10,1,Ou)
else:
Deal(2,10,2,Ou,True)
else:
if temp == left_arr]:
standard = left_arr]
if dic['index'] < dic['bits'] - 1:
Deal(9,max(),-1,Ou)
else:
Deal(8,max(),-2,Ou,True)
else:
if dic['index'] < dic['bits'] - 1:
Deal(1,10,1,Ou)
else:
Deal(2,10,2,Ou,True)
else:
if right_arr] == left_arr]:
s1 = left_arr]
s2 = right_arr]
if dic['index'] < dic['bits'] - 1:
Deal(max(),s2+1,1,Ou)
else:
Deal(max(),s2+1,2,Ou,True)
else:
if temp < right_arr] and temp > left_arr]:
if dic['index'] < dic['bits'] - 1:
Deal(1,10,1,Ou)
else:
Deal(2,10,2,Ou,True)
elif temp == right_arr]:
standard = right_arr]
if dic['index'] < dic['bits'] - 1:
Deal(1,standard+1,1,Ou)
else:
Deal(2,standard+1,2,Ou,True)
else:
standard = left_arr]
if dic['index'] < dic['bits'] - 1:
Deal(9,max(),-1,Ou)
else:
Deal(8,max(),-2,Ou,True)
def Deal(start,end,step,func,mode = False):
for each in range(start,end,step):
temp.append(each)
if mode == False:
dic['index'] += 1
func()
temp.pop()
else:
Num = digital2num(temp)
Div = GongBei(set(temp))
if Num % Div == 0:
result.append(Num)
temp.pop()
dic['index'] -= 1
if left == right:
temp = num2digital(left)
Div = GongBei(set(temp))
if left % Div == 0:
return
else:
return []
if right <= 10:
return
elif left < 10:
result =
left = 10
else:
result = []
left_arr = num2digital(left)
m = len(left_arr)
right_arr = num2digital(right)
M = len(right_arr)
dic = {'index':0,'bits':0}
if m!=M:
for each in range(m,M+1):
temp = []
dic['bits']=each
Ji()
dic['index']=0
Ou()
dic['index']=0
else:
for i in range(1,m):
if left_arr!=right_arr:
break
dic['bits']=m
dic['index']=i-1
temp = []
temp.extend(left_arr)
Ji()
dic['index']=i-1
temp = []
temp.extend(left_arr)
Ou()
result.sort()
return result
TJBEST
发表于 2020-3-18 18:47:25
楼主,可能我的代码太长了,还需要审核{:5_104:} 。。。
小甲鱼de粉丝
发表于 2020-3-18 19:17:06
来了,刚看到,写个无脑版本。
def day354(left, right):
numberlist = []
nnl = []
for i in range(left ,right):
numberlist.append(i + 1)
for i in range(len(numberlist)):
number = numberlist
nlist = list(str(number))
pass1 = 0
for each in range(len(str(number))):
if int(nlist) == 0:
pass1 += 1
elif number % int(nlist) == 0:
pass1 += 1
if pass1 == len(str(number)):
nnl.append(number)
print(nnl)
小甲鱼de粉丝
发表于 2020-3-18 19:18:51
fan1993423 发表于 2020-3-17 17:39
这道题思路很容易想到,但考虑到是效率题,所以还是要从效率入手。在323055,41520421这数据,我测了下是14 ...
10不是吗 ,我输1,10
小甲鱼de粉丝
发表于 2020-3-18 19:27:03
小甲鱼de粉丝 发表于 2020-3-18 19:17
来了,刚看到,写个无脑版本。
我重发
def day354(left, right):
if not(left < 1):
numberlist = []
nnl = []
for i in range(left ,right):
numberlist.append(i + 1)
for i in range(len(numberlist)):
pass2 = 1
number = numberlist
nlist = list(str(number))
pass1 = 0
for i2 in nlist:
if i2 == "0":
pass2 = 0
if not(pass2 == 0):
for each in range(len(str(number))):
if int(nlist) == 0:
pass1 += 1
elif number % int(nlist) == 0:
pass1 += 1
if pass1 == len(str(number)):
nnl.append(number)
print(nnl)
小甲鱼de粉丝
发表于 2020-3-18 19:33:49
小甲鱼de粉丝 发表于 2020-3-18 19:27
我重发
这个,抱歉,发现有bug{:10_291:}
def day354(left, right):
if not(left < 1):
numberlist = []
nnl = []
numberlist.append(1)
for i in range(left ,right):
numberlist.append(i + 1)
for i in range(len(numberlist)):
pass2 = 1
number = numberlist
nlist = list(str(number))
pass1 = 0
for i2 in nlist:
if i2 == "0":
pass2 = 0
if not(pass2 == 0):
for each in range(len(str(number))):
if int(nlist) == 0:
pass1 += 1
elif number % int(nlist) == 0:
pass1 += 1
if pass1 == len(str(number)):
nnl.append(number)
print(nnl)
永恒的蓝色梦想
发表于 2020-3-18 20:21:43
TJBEST 发表于 2020-3-18 18:42
这个比暴力破解时间的40%左右 速度有点进步,但是代码超机长。累死我了
兄弟,你这个码好像不是太快……{:10_262:}
fan1993423
发表于 2020-3-18 20:21:43
小甲鱼de粉丝 发表于 2020-3-18 19:18
10不是吗 ,我输1,10
我的意思是大数据可能会超时,版主出题要不就是比较难,要不就是简单但要求大数据通过且高效率
永恒的蓝色梦想
发表于 2020-3-18 20:23:55
fan1993423 发表于 2020-3-18 20:21
我的意思是大数据可能会超时,版主出题要不就是比较难,要不就是简单但要求大数据通过且高效率
其实力扣的测试都比较简单的{:10_248:}
fan1993423
发表于 2020-3-18 20:27:11
永恒的蓝色梦想 发表于 2020-3-18 20:23
其实力扣的测试都比较简单的
放心好了,版主一定会哪个大数据来测的,先来小数据看对不对,然后用大数据测时间
永恒的蓝色梦想
发表于 2020-3-18 20:31:18
fan1993423 发表于 2020-3-18 20:27
放心好了,版主一定会哪个大数据来测的,先来小数据看对不对,然后用大数据测时间
也许你是对的吧{:10_248:}
TJBEST
发表于 2020-3-18 20:45:08
本帖最后由 TJBEST 于 2020-3-18 20:46 编辑
永恒的蓝色梦想 发表于 2020-3-18 20:21
兄弟,你这个码好像不是太快……
我主要练习自己的逻辑性,练习编码。公司项目,一般也不会让你编这个。重在练习。用的时候,直接百度就行,而且用python考虑速度有点本末倒置。c++和c岂不美哉{:5_109:}
fan1993423
发表于 2020-3-18 20:51:08
TJBEST 发表于 2020-3-18 20:45
我主要练习自己的逻辑性,练习编码。公司项目,一般也不会让你编这个。重在练习。用的时候,直接百度就 ...
你们公司主要是做哪些项目。对,将效率的确python有先天劣势
永恒的蓝色梦想
发表于 2020-3-18 20:52:22
TJBEST 发表于 2020-3-18 20:45
我主要练习自己的逻辑性,练习编码。公司项目,一般也不会让你编这个。重在练习。用的时候,直接百度就 ...
好吧
TJBEST
发表于 2020-3-18 20:53:09
fan1993423 发表于 2020-3-18 20:51
你们公司主要是做哪些项目。对,将效率的确python有先天劣势
我们都是外包,我们只管审查,调试。主要是JAVA。水的一比
小甲鱼de粉丝
发表于 2020-3-18 21:10:15
fan1993423 发表于 2020-3-18 20:21
我的意思是大数据可能会超时,版主出题要不就是比较难,要不就是简单但要求大数据通过且高效率
恩