赞
踩
目录
做了三个小时,和去年相比,也就能多做一个dijkstra
其他的地方看着根本没思路,看了看答案也都是动归,dfs,bfs,但是以我目前的理解,好像用不到这上面
这次就当体验一下题目了,接下来的两个月重点抓动归和搜索
答案为3181
- hash=[0 for i in range(10)]
- i=1
- while(i):
- string=str(i)
- for j in string:
- hash[int(j)]+=1
- if hash[int(j)]==2021:
- print(i)
- i=0
- break
- if i==0:
- break
- else:i+=1
python小数运算会搞怪
- def getline(a,b):
- if b[0]-a[0]==0:
- k=-1<<31
- b=b[0]
- else:
- k=(b[1]-a[1])/(b[0]-a[0])
- b=b[1]-k*b[0]
- return (k,b)
- point=[]
- for i in range(20):
- for j in range(21):
- point.append((i,j))
- ans=[]
- for i in range(len(point)):
- for j in range(i+1,len(point)):
- line=getline(point[i],point[j])
- if line not in ans:
- ans.append(line)
- print(len(ans))
- def gcd(a,b):
- if b==0:
- return a
- return gcd(b,a%b)
- def getmin(a,b):
- return a*b//gcd(a,b)
- adj=[[]for i in range(2022)]
- for i in range(1,2022):
- left,right=-1,-1
- if i<21:
- left=1
- right=i+21
- elif i>2000:
- left=i-21
- right=2021
- else:
- left=i-21
- right=i+21
- for j in range(left,right+1):
- length=getmin(i,j)
- adj[i].append((j,length))
- d=[1<<31 for i in range(2022)]
- vis=[False for i in range(2022)]
- def dijkstra():
- d[1]=0
- for i in range(2021):
- minlength=1<<31
- minindex=-1
- for j in range(1,2022):
- if not vis[j] and d[j]<minlength:
- minlength=d[j]
- minindex=j
- if minindex==-1:
- return
- vis[minindex]=True
- for point in adj[minindex]:
- index=point[0]
- length=point[1]
- if not vis[index] and d[index]>d[minindex]+length:
- d[index]=d[minindex]+length
- dijkstra()
- print(d[2021])
- def gcd(a,b):
- if b==0:
- return a
- return gcd(b,a%b)
- adj=[[]for i in range(22)]
- for i in range(1,22):
- for j in range(i+1,22):
- if gcd(i,j)==1:
- adj[i].append(j)
- adj[j].append(i)
-
- vis=[False for i in range(22)]
- ans=0
- length=0
- def dfs(cur):
- global vis
- global ans
- global length
- if 1 in adj[cur] and False not in vis:
- ans+=1
- return
- if False not in vis:
- return
- for i in adj[cur]:
- if not vis[i]:
- vis[i]=True
- dfs(i)
- vis[i]=False
- return
- # for i in adj:
- # print(i)
- vis[0]=True
- vis[1]=True
- dfs(1)
- print(ans)
- a=int(input())
- day=24*60*60
- s=a//1000
- s=s%day
- h=s//3600
- lst=s%3600
- m=lst//60
- s=lst%60
- print("{:02d}:{:02d}:{:02d}".format(h,m,s))
- a=int(input())
- dp=[[0 for i in range(a)]for i in range(a)]
- dp[0][0]=1
- cur=1
- def finds():
- for i in range(1,a):
- dp[i][0]=1
- dp[i][i]=1
- for j in range(1,i):
- dp[i][j]=dp[i-1][j-1]+dp[i-1][j]
- if dp[i][j]==a:
- cur=(i*(i+1))//2+1+j
- return cur
- print(finds())
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。