上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 47 下一页
摘要: #做法1: 使用内置函数Fraction from fractions import Fraction while True: try: a,b=map(int,input().split("/")) print(Fraction(a,b)) except: break 做法2:手写gcd **知识 阅读全文
posted @ 2022-05-31 16:53 kingwzun 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 递归 def sum(n,deep): sums = 0 # print(deep) for i in n: if isinstance(i, list): sums += sum(i,deep+1) if isinstance(i, int): sums += deep return sums a 阅读全文
posted @ 2022-05-30 20:16 kingwzun 阅读(45) 评论(0) 推荐(0) 编辑
摘要: from itertools import permutations n=int(input()) for i in permutations(list( range(1,n+1) )): print("".join(map(str,i))) 阅读全文
posted @ 2022-05-30 17:20 kingwzun 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 扩展: 蒙特卡罗算法: 蒙特卡罗方法(英语:Monte Carlo method),也称统计模拟方法,是1940年代中期由于科学技术的发展和电子计算机的发明,而提出的一种以概率统计理论为指导的数值计算方法。是指使用随机数(或更常见的伪随机数)来解决很多计算问题的方法。 解释: 假设我们要计算一个不规 阅读全文
posted @ 2022-05-30 12:09 kingwzun 阅读(86) 评论(0) 推荐(0) 编辑
摘要: 原文 知识点: 这个else用的很灵性,学习到了 list的index的使用 l=[int(x) for x in input().split()] num=int(input()) d={} for i in l: d[i]=num-i for key,value in d.items(): if 阅读全文
posted @ 2022-05-30 11:46 kingwzun 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 知识点: sort函数的排序规则key的使用 代码: dit1=dict(eval(input())) dit2=dict(eval(input())) for i,j in dit1.items(): dit2[i]=dit2.get(i,0)+j ans=list(dit2.items()) a 阅读全文
posted @ 2022-05-30 11:27 kingwzun 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 知识点:sorted函数(dict默认10比2小) n=int(input()) num=[int(x) for x in input().split()] mp={} for i in num: mp.setdefault(i,0) mp[i]=mp[i]+1 for i,j in sorted( 阅读全文
posted @ 2022-05-30 10:48 kingwzun 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 知识点: 使用eval函数 a=input() x=input() b=input() c=a+x+b if(int(b)==0 and x=="/"): print("divided by zero") else: print("{:.2f}".format(eval(c))) ``` 阅读全文
posted @ 2022-05-30 10:40 kingwzun 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 解1: 使用dist n=input() mp={} for i in n: mp.setdefault(i,0) mp[i]=mp[i]+1 k=input() print(mp[k]) 解2: 使用count函数 n = input() k = input() print(n.count(k)) 阅读全文
posted @ 2022-05-30 10:33 kingwzun 阅读(96) 评论(0) 推荐(0) 编辑
摘要: n=int(input()) num=0 sum=0 for i in range(n): dic=eval(input()) for j in dic: temp=dic[j] num+=len(temp) for key in temp: sum+=temp[key] # print(" ") 阅读全文
posted @ 2022-05-30 10:14 kingwzun 阅读(91) 评论(0) 推荐(0) 编辑
上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 47 下一页