贴几道自己做过的py题防止忘了,好像包含的语法还挺多的
洛谷1018
nn,mm=input().split(' ')
o=int(input())
n=int(nn);m=int(mm)
a=[[]];c=[[]]
for i in range (1,43):
a.append([]);c.append([])
for i in range (1,43):
for j in range (1,43):
a[i].append(0),c[i].append(0)
b=[]
for i in range (1,43):
b.append(0)
for i in range (1,n+1):
b[n+1-i]=o-(o//10*10);o=o//10
for i in range (1,n+1):
c[i][i]=b[i]
for j in range (i+1,n+1):
c[i][j]=c[i][j-1]*10+b[j]
for i in range (1,n+1):
a[1][i]=c[1][i];
for i in range (2,m+2):
for j in range (i,n+1):
for k in range (i-1,j):
if (a[i-1][k]*c[k+1][j]>a[i][j]):
a[i][j]=a[i-1][k]*c[k+1][j]
print(a[m+1][n])
洛谷3904
a=[[]]
for i in range (1,53):
a.append([])
for i in range (0,53):
for j in range (0,53):
a[i].append(0)
a[0][0]=1
nn,mm=input().split(' ')
n=int(nn);m=int(mm)
if (n<m):
print(0)
else:
k=0
for i in range (1,n+1):
k=i
if (m<i):
k=m
for j in range (1,k+1):
a[i][j]=a[i-1][j-1]+j*a[i-1][j]
print(a[n][m])
洛谷2293
50分暴力
import math
a=int(input())
b=int(input())
print(math.floor(math.pow(b,1/a)+0.000000001))
AC代码
a=int(input())
b=int(input())
l=0
r=1
while(r**a<=b):
l=r;r=r*2
while(l+1<r):
mid=(l+r)//2
if (mid**a<=b):
l=mid
else:
r=mid
if (l**a<=b):
print(l)
else:
print(r)
洛谷2613
mo=19260817
def ksm(x,y):
ans=1
while(y>0):
if (y%2==1):
ans=ans*x%mo
y//=2
x=x*x%mo
return ans
x=int(input())%mo
y=int(input())%mo
if (y==0):
print("Angry!")
else:
print(x*ksm(y,mo-2)%mo)
洛谷2152
import fractions
print(fractions.gcd(int(input()),int(input())))
洛谷2144
n=int(input())
x=1
y=3
z=3
while(z<=n):
xx=y;y=y+x;x=xx;z=z+1
y=y*y
if (n%2==0):
y=y-4
if (n==1):
print(1)
else:
print(y)