The last set before the exam! Lanqiao Cup python group first year provincial competition real questions

foreword

Let us have vigorous memories today, like the graduation season!
I will take the exam tomorrow. How are you preparing? Have you reviewed the corresponding modules? Have you mastered the basics? I will put a mind map made by myself for everyone to recall the process.
insert image description here
The following is the topic of the Python 2020 Provincial Competition, because it is the first time, and it is also catching up with the Year of the Gengzi Rat, purely winning.

A: house number making

insert image description here

ans=0
for i in range(1,2021):
  ans+=str(i).count('2')
print(ans)

Spike question, spike question

B: Looking for 2020

insert image description here
Compared with the classic DFS, be careful not to go beyond the bounds, just judge one by one direction

import os
import sys
N=300
data=[list(input()) for _ in range(N)]
row=len(data)
col=len(data[0])
res=0
for i in range(row):
    for j in range(col):
        if data[i][j]=='2':
            if j<=col-4 and data[i][j+1]=='0' and data[i][j+2]=='2' and data[i][j+3]=='0':
                res+=1
            if i<=row-4 and data[i+1][j]=='0' and data[i+2][j]=='2' and data[i+3][j]=='0':
                res+=1
            if i<=row-4 and j<=col-4 and data[i+1][j+1]=='0' and data[i+2][j+2]=='2' and data[i+3][j+3]=='0':
                res+=1
print(res)            

C: Running and exercising

insert image description here

import datetime
start=datetime.datetime(2000,1,1)
end=datetime.datetime(2020,10,1)
delta=datetime.timedelta(days=1)
ans=0
while start<=end:
  if start.weekday()==0 or start.day==1:
    ans+=2
  else:
    ans+=1
  start+=delta
print(ans)

Recite the whole text, recite the whole text, the date question in Python is very simple, don’t lose points, delta represents the difference, days is the unit, the datetime type instance has the attribute of day to represent the day of the month, the weekday() function judges Take a look at the official documents for the day of the week (0-6)
insert image description here
insert image description here
, you will have to use it tomorrow hehe

D: Serpentine filling

insert image description here
I remember this is regular, take a pen to push it, borrow a picture from the Internet
insert image description here

ans=1
for i in range(1,20):
	ans+=i*4
print(ans)

E: Sort

insert image description here
This is a special case.
Considering the complexity of bubble sorting, N letters need to be exchanged at most N*(N-1)/2 times (when completely out of order). It is easy to know that when
N=15, there are 15*14/2=105 , that is, the shortest string required to satisfy 100 swaps has 15 letters.
If the smallest lexicographic order is required, then take the 15 letters a~o with the smallest lexicographical
order and think backwards. After the target string is exchanged 100 times, the positive sequence string abcdefghijklmno is obtained, and the completely reversed string onmlkjihgfedcba becomes the positive sequence character The string needs 105 exchanges, so after exchanging the completely reversed string 5 times, you can get the answer. Because the smallest lexicographical order is required, then swapping j 5 times and bringing it to the front of the string will get the smallest case

F: Results statistics

insert image description here
insert image description here

free

n=int(input())
jg=0
yx=0
for i in range(n):
  t=int(input())
  if t>=60:
    jg+=1
  if t>=85:
    yx+=1
print(round(jg/n*100),end="%")
print()
print(round(yx/n*100),end="%")

G: word analysis

insert image description here

s=input()
num=0
c=' '
for i in s:
    if s.count(i)>num:
        num=s.count(i)
        c=i
print(c)
print(num)

Don't think too complicated, focus on a count

H: Number triangle

insert image description here
DP, there are three directions, the leftmost: the lower left corner can only be used for the upper right corner, the last side: the lower right corner can only be used for the upper left corner, the middle is normal, the output must follow the requirements of the topic, the direction offset cannot exceed 1, and the odd line is the middle That, the even rows are the comparison of the middle two

n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
for i in range(1,n):
    for j in range(i+1):
        if j==0:
            arr[i][j]+=arr[i-1][j]
        elif j==i:
            arr[i][j]+=arr[i-1][j-1]
        else:
            arr[i][j]+=max(arr[i-1][j-1],arr[i-1][j])
else:
    if n%2==0:
        print(max(arr[i][n//2-1],arr[i][n//2])
    else:
        print(arr[i][n//2])

I: plane segmentation

insert image description here
Let’s think about this question first. At the beginning, it is a plane, + a straight line becomes two, and there are two situations when adding a straight line. One is that
it intersects with the first line at an intersection, and the current two planes It is divided into 4; the other is that it overlaps or is parallel to the first one, the total number is +1,
so add a straight line at random, at least one, and the variable is the number of intersections between it and other straight lines

n=eval(input())
line=[tuple(map(int,input().split(" "))) for i in range(n)]#用元组收集(k,b)
s=set(line)#去除重复的直线
line=list(s)
if line:
	ans=2#如果有直线,那么至少两个平面
	for i in range(1,len(line)):
		a1,b1=line[i]
		pos=set()#交点集合
		for j in range(i):#取出当前直线前面的直线斜率进行比较
			a2,b2=line[j]
			if a1==a2:#平行或重合
				continue
			x=(b1-b2)/(a1-a2)
			y=a1*x+b1
			pos.add((x,y))#收集交点
		ans+=len(pos)+1#交点数+1
print(ans)

J: Orbs

Let's not read this question

epilogue

Huh~ I finished the last set, I feel relaxed, I will sleep well tonight, and I will go to the examination room to test the machine half an hour earlier tomorrow.
The mind map I promised everyone is not finished yet. I am recalling the content of the previous blog. It may take a while. I will put a general structure here. Those who want to see it can leave a message in the comment area and send it to everyone after the production is completed.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_53415043/article/details/130006211