current position:Home>Python implementation of official selection sorting of Luogu question list
Python implementation of official selection sorting of Luogu question list
2022-05-15 05:25:00【Q Tianma a XingKong Q】
Catalog
- P1271 【 Deep base 9. example 1】 Election of Student Union
- P1177 【 Templates 】 Quick sort
- P1923 【 Deep base 9. example 4】 Please k Small number
- P1059 [NOIP2006 Popularization group ] A clear random number
- P1781 Cosmic president
- P2676 [USACO07DEC]Bookshelf B
- P1116 Carriage reorganization
- P1152 Happy jump
- P1068 [NOIP2009 Popularization group ] The score line is drawn
- P5143 Scrambler
- P1104 Birthday
- P1012 [NOIP1998 Improvement group ] Spell numbers
P1271 【 Deep base 9. example 1】 Election of Student Union
n,m=map(int,input().strip().split())
ls=[int(i) for i in input().strip().split()]
ls.sort()
for i in ls:
print(i,end=" ")
P1177 【 Templates 】 Quick sort
N=int(input().strip())
ls=[int(i) for i in input().strip().split()]
ls.sort()
for i in ls:
print(i,end=" ")
P1923 【 Deep base 9. example 4】 Please k Small number
import numpy as np
n, k = map(int, input().split())
arr = np.fromstring(input(), dtype = np.uint32, sep=' ')
arr.sort()
print(arr[k])
notes :Python There seems to be no and C++ Medium nth_element() Functions with the same function , Only use sort() Sort first and then find the k The number of bits , because Python The default integer in is 64 Bit form , Therefore, sorting will result in the last two points MLE, So you have to use fromstring() Function int To numpy Unique in Library 32 A form of , Yes, the detection machine in Los Angeles has numpy.
P1059 [NOIP2006 Popularization group ] A clear random number
n=input()
ls1=[int(i) for i in input().strip().split()]
ls2=[i for i in set(ls1)]
ls2.sort()
print(len(ls2))
for i in ls2:
print(i,end=" ")
P1781 Cosmic president
def hanshu(a,b):
c,d=len(a),len(b)
if c<d:
return False
if c>d:
return True
for i in range(c):
e,f=int(a[i]),int(b[i])
if e>f:
return True
if e<f:
return False
n=int(input().strip())
i,j=None,None
for k in range(1,n+1):
m=input().strip()
if i==None:
i,j=m,k
else:
if hanshu(m,i)==True:
i,j=m,k
print(j)
print(i)
P2676 [USACO07DEC]Bookshelf B
N,B=map(int,input().strip().split())
ls=[]
for i in range(N):
ls.append(int(input().strip()))
ls.sort(reverse=True)
cnt1=0
cnt2=0
while True:
cnt1+=ls[cnt2]
cnt2+=1
if cnt1>=B:
break
print(cnt2)
P1116 Carriage reorganization
a=int(input())
b=[]
while len(b)<a:
b+=[int(i) for i in input().split()]
c=0
for d in range(a):
for e in range(0, a-d-1):
if b[e] > b[e+1] :
b[e], b[e+1] = b[e+1], b[e]
c=c+1
print(c)
notes : The input of this problem is far from the general .
P1152 Happy jump
ls=[int(i) for i in input().strip().split()]
n,ls=ls[0],ls[1:]
ls1=[i for i in range(1,n)]
ls2=[]
for i in range(n-1):
c=abs(ls[i]-ls[i+1])
ls2.append(c)
ls2.sort()
if ls2==ls1:
print("Jolly")
else:
print("Not jolly")
P1068 [NOIP2009 Popularization group ] The score line is drawn
from math import floor
def hanshu(ls):
x=len(ls)
for i in range(x-1):
for j in range(x-i-1):
if ls[j][1]==ls[j+1][1]:
if ls[j][0]>ls[j+1][0]:
ls[j],ls[j+1]=ls[j+1],ls[j]
for i in ls:
print(i[0],i[1])
n,m=map(int,input().strip().split())
ls=[]
for i in range(n):
a,b=map(int,input().strip().split())
ls.append([a,b])
ls=sorted(ls,key=lambda x:x[1],reverse=True)
x=floor(m*1.5)
a=ls[x-1][1]
b=x
sl=ls[:x]
for i in range(x,n):
if ls[i][1]>=a:
sl.append(ls[i])
b+=1
else:
break
print(a,b)
ls=[]
for i in sl:
if ls==[]:
x=i[1]
if i[1]==x:
ls.append(i)
else:
hanshu(ls)
x=i[1]
ls=[i]
hanshu(ls)
notes : Maybe I wrote it complicated . I originally had a very simple code , But it's a little overtime , Sobbing . This code , From a large list , Make a small list of the same scores , Then bubble sort the small list according to the registration number . Then output the elements of the small list in turn .
P5143 Scrambler
def hanshu(a,b,c):
return pow(a**2+b**2+c**2,1/2)
N=int(input())
ls=[]
for i in range(N):
a,b,c=map(int,input().strip().split())
ls.append([a,b,c])
ls=sorted(ls,key=lambda x:x[2])
cnt=0
for i in range(N-1):
cnt+=hanshu(ls[i+1][0]-ls[i][0],ls[i+1][1]-ls[i][1],ls[i+1][2]-ls[i][2])
print("%.3f"%(cnt))
P1104 Birthday
import datetime
x=datetime.date(1800,1,1)
n=int(input().strip())
ls=[]
for i in range(n):
a,b,c,d=input().strip().split()
b,c,d=int(b),int(c),int(d)
y=datetime.date(b,c,d)
z=(y-x).days
if ls==[]:
ls.append([z,a])
else:
for i in ls:
if z>i[0]:
j=ls.index(i)
ls.insert(j,[z,a])
break
else:
ls.append([z,a])
ls=ls[::-1]
for i in ls:
print(i[1])
notes : Go straight to a far time , Just find out the number of days from everyone's birthday to this era , There's no need to compare year, month and day next to each other .
P1012 [NOIP1998 Improvement group ] Spell numbers
def hanshu( list ,x,y):
global sl
if x==y:
z=""
for i in list :
z+=i
sl.append(int(z))
else:
for i in range(x,y):
list [x], list [i]= list [i], list [x]
hanshu( list ,x+1,y)
list [x], list [i]= list [i], list [x]
n=int(input().strip())
ls=input().strip().split()
sl=[]
hanshu(ls,0,n)
print(max(sl))
notes : Recursively create all numbers , Find the maximum value directly
copyright notice
author[Q Tianma a XingKong Q],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/131/202205111214482190.html
The sidebar is recommended
- Build Python project in Jenkins, pychar output is normal and Jenkins output modulenotfounderror: no module named problem
- Interface request processing of Python webservice
- Download third-party libraries offline in Python
- Web automation in Python
- Importlib.exe in Python import_ Module import module
- Operation of OS Library in Python
- Some integration operations on Web pages in Python
- Python realizes the super fast window screenshot, automatically obtains the current active window and displays the screenshot
- Implementation of workstation monitoring system with Python socket
- Resume Automation - word 92
guess what you like
Django foundation -- 02 small project based on Database
Python drawing word cloud
Django foundation -- 02 small project based on Database
MNIST dataset classification based on Python
Design of FTP client server based on Python
Signing using RSA algorithm based on Python
Website backend of online book purchase function based on Python
Implementation of Tetris game based on Python greedy search
Django Foundation
Case: Python weather broadcast system, this is a rainy day
Random recommended
- Python development alert notification SMS alert
- How to configure Python environment library offline in FME
- Python: fastapi - beginner interface development
- Generate password based on fast token and fast token
- [Django CI system] use of json-20220509
- [Django CI system] if the front-end date is complete, it will be fully updated to the back-end; If the front-end date is incomplete, the date will not be updated to the back-end-20220510
- [Django CI system] echarts dataset standard writing - 20220509
- [Django CI system] obtain the current time, the first day and the last day of the month, etc. - 20220510
- wxPython wx. Correction of font class · Wx Font tutorial
- NCT youth programming proficiency level test python programming level 3 - simulation volume 2 (with answers)
- Design of personal simple blog system based on Django (with source code acquisition method)
- [Python Script] classify pictures according to their definition
- Wu Enda's classic ml class is fully upgraded! Update to Python implementation and add more intuitive visual teaching
- Six built-in functions called immortals in Python
- Some insights of pandas in machine learning
- Introduction to Python [preliminary knowledge] - programming idea
- Stay up late to tidy up! Pandas text processing Encyclopedia
- Python recursion to find values by dichotomy
- Open 3D Python Interface
- [true title 02 of Blue Bridge Cup] Python output natural number youth group analysis of true title of Blue Bridge Cup Python national competition
- Introduction to the differences between Python and Java
- Explain Python CONDA in detail
- The pycham downloaded by MAC reports an error as soon as it is opened. The downloaded Python interpreter is also the latest version
- From entry to mastery, python full stack engineers have personally taught Python core technology and practical combat for ten years
- Python is used to detect some problems of word frequency in English text.
- How to choose between excel, database and pandas (Python third-party library)?
- WxPython download has been reporting errors
- Pyside6 UIC and other tools cannot be found in the higher version of pyside6 (QT for Python 6). How to solve it?
- About Python Crawlers
- Successfully imported pandas, unable to use dataframe
- How to extract some keywords in the path with Python
- Python encountered a problem reading the file!
- When Python is packaged into exe, an error is reported when opening assertionerror: C: \ users \ Acer \ appdata \ local \ temp\_ MEI105682\distutils\core. pyc
- Eight practical "no code" features of Python
- Python meets SQL, so a useful Python third-party library appears
- 100 Python algorithm super detailed explanation: a hundred dollars and a hundred chickens
- [fundamentals of Python] Python code and so on
- When Python uses probit regression, the program statement is deleted by mistake, and then it appears_ raise_ linalgerror_ Unrecognized error of singular
- Python testing Nicholas theorem
- Accelerating parallel computing based on python (BL) 136