CCF CSP认证

202209-1

n,m=map(eval,input().split())
list_a=list(map(int,input().split()))
# print(n,m)
# print(list_a)

# n,m=7,23333
# list_a=[3, 5, 20, 10, 4, 3, 10]
list_c=[1]
list_b=[]
for i in list_a:
    list_c.append(list_c[-1]*i)
temp=0
try:
    for i in range(len(list_c)):
        # print("{}-{}".format(i, list_c[i]))
        b=(m%list_c[i+1])/list_c[i]
        x=b*list_c[i]
        m=m-x
        list_b.append(b)
except:
    pass

list_b=map(int,list_b)
print(*list_b)

试题编号: 202212-2
试题名称: 训练计划

n, m = map(int,input().split())
p = [0]+[i for i in map(int,input().split())]
t = [0]+[i for i in map(int,input().split())]

# n, m =10,7
# p=[0,0, 1 ,0 ,3 ,2, 3, 0]
# t=[0,2, 1, 6 ,3 ,10, 4, 3]

earliest = [0 for _ in range(m+1)]
latest = [0 for _ in range(m+1)]
line = [0 for _ in range(m+1)]

mark=True
for i in range(1,m+1):
    if p[i]==0:
        earliest[i]=1
    else:
        earliest[i]=earliest[p[i]]+t[p[i]]
    
print(*earliest[1:])


def fun (p,t,index):
    if p[index]==0:
        return t[index]
    else:
        return t[index]+fun(p,t,p[index])

try:
    if mark==True:
        for i in range(m,0,-1):
            if p[i]==0:
                latest[i]=n-t[i]+1
            else:
                latest[i]=n-(fun (p,t,i))+1
            if latest[i]<=0:
                mark=False
    if mark==True:
        print(*latest[1:])
except:
    pass

CCF 202109-1 数组推导

n=input()
b_list=list(map(eval,input().split()))
# print(n)
# print(b_list)

# test_n=int(input())
# if test_n==0 :
#     n=6
#     b_list=[0,0, 0, 5, 5, 10, 10]
# else:
#     n=7
#     b_list=[0,0,10 ,20, 30 ,40 ,50 ,60, 75]

max=sum(b_list)
# min=set(b_list)
min=sum(list(set(b_list)))
print(max)
print(min)

试题编号: 202104-1

试题名称: 灰度直方图

n,m,l=map(eval,input().split())
im=[0 for i in range(l)]
for i in range(n):
    l=list(map(int,input().split()))
    for j in l:
        im[j]=im[j]+1
print(*im)
    
    

csp 202104-2 (二维前缀和思想)

https://www.bilibili.com/video/BV1pi4y1j7si?p=3&vd_source=a55a729a8abbc793a24a2504a9067a76
试题名称:邻域均值
试题背景:顿顿在学习了数字图像处理后,想要对手上的一副灰度图像进行降噪处理。不过该图像仅在较暗区域有很多噪点,如果贸然对全图进行降噪,会在抹去噪点的同时也模糊了原有图像。因此顿顿打算先使用邻域均值来判断一个像素是否处于较暗区域,然后仅对处于较暗区域的像素进行降噪处理。

n,l,r,t=map(int,input().split())
data=[]
count=0
for i in range(n):
    data.append(list(map(int,input().split())))

# n,l,r,t=4 ,16, 1 ,6
# data=[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]

count=0
sum=[[0]*(n+1) for i in range(n+1)]
# 创建前缀和数组,存放的是(i,j)与(1,1)所围成矩形区域内数的和
for i in range(1,n+1):
    for j in range(1,n+1):
        sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+data[i-1][j-1]
# 判定在邻域范围内,数值和小于阈值的数有多少。

for i in range(1,n+1):
    for j in range(1,n+1):
        sub_count=0
        i_min=max(1,i-r)-1
        i_max=min(n,i+r)
        j_min=max(1,j-r)-1
        j_max=min(n,j+r)
        sub_sum=sum[i_max][j_max]-sum[i_max][j_min]-sum[i_min][j_max]+sum[i_min][j_min]
        num=(i_max-i_min)*(j_max-j_min)
        sub_count=sub_sum/num
        if(sub_count <= t):
            count=count+1
print(count)        

包邮问题

n,x=map(int,input().split())
# 设置a来存储每个数的价格
a=[]
# 设置动态规划数组存储每个价格的最小花费
dp=[0]*(n*x)
for i in range(n):
    t=int(input())
    a.append(t)
#pre保存目前满足包邮的最小花费
pre=sum(a)
# 01背包解法,将每个地方的最优解存入dp数组中
# print(dp)
# print(len(dp))
for i in range(n):
    for j in range(pre,a[i]-1,-1):
        dp[j]=max(dp[j],dp[j-a[i]]+a[i])
# print(dp)    
out=set(dp)
for i in dp:
    if dp[i]>=x:
        print(dp[i])
        break

202206-2 寻宝大冒险

# 输入三个正整数 n、L 和 S,分别表示西西艾弗岛上树的棵数、绿化图和藏宝图的大小
n,l,s=map(int,input().split())
# 输入每棵树的坐标
points=[]
for i in range(n):
    points.append(list(map(int,input().split())))
# 将树的坐标整理成集合的形式,方便后面进行地图与树位置的比对

temp={}
for point in points:
    x,y=point[0],point[1]
    temp[(x,y)]=1

money=[]
for i in range(s+1):
    money.insert(0, list(map(int, input().split())))

count=0


for x,y in points:
    flag=0
    for i in range(s+1):
        for j in range(s+1):
            #如果索引越界
            if(x+i>l) or (y+j>l):
                flag=1
                break
            #如果藏宝图山此处有树
            if money[i][j]==1:
                if (x+i,y+j) not in temp:
                    flag=1
                    break
            #如果藏宝图此处无数,但地图有树
            else:
                if(x+i,y+j) in temp:
                    flag=1
                    break
        if flag==1:
            break
    if flag ==0:
        count+=1
print(count)
  

202212-3 JPEG 解码(python100分):

import math
q=[]
for i in range(8):
    temp=list(map(int,input().split()))
    q.append(temp)
n=int(input())
T=int(input())
list_m=list(map(int,input().split()))

# n=64
# T=0
# list_m=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
# print(list_m)
# q=[[16, 11, 10, 16, 24, 40, 51, 61], [12, 12 ,14, 19, 26, 58, 60 ,55], [14, 13, 16, 24, 40, 57, 69, 56], [14, 17 ,22, 29 ,51, 87 ,80 ,62], [14, 13, 16, 24, 40, 57, 69, 56], [24, 35, 55, 64, 81, 104, 113, 92], [24, 35, 55, 64, 81, 104, 113, 92], [72, 92, 95, 98, 112, 100, 103, 99]]

m=[]
for i in range(8):
    m.append([0,0,0,0,0,0,0,0])

def fun_guide():
    ls=[]

    move1=[[0,1],[1,-1],[1,0],[-1,1]]
    move2=[[-1,1],[1,0],[1,-1],[0,1]]
    
    move_way=0
    tem_location=[0,0]
    for i in range(0,36):
        ls.append(list(tem_location))
        tem_location[0]=tem_location[0]+move1[move_way][0]
        tem_location[1]=tem_location[1]+move1[move_way][1]
        if 0 in tem_location:
            move_way=(move_way+1)%4
    
    # print("-------")
    move_way=0
    tem_location=[7,1]
    for i in range(36,64):
        ls.append(list(tem_location))
        tem_location[0]=tem_location[0]+move2[move_way][0]
        tem_location[1]=tem_location[1]+move2[move_way][1]
        if 7 in tem_location:
            move_way=(move_way+1)%4
    return ls


ls=fun_guide()

for index,value  in enumerate(list_m) :
    y,x=ls[index][0],ls[index][1]
    m[y][x]=value
    

if T==0:
    for i in range(8):
        print(*m[i])
elif T==1:        
    for x in range(8):
        for y in range(8):
            m[x][y]=m[x][y]*q[x][y]
    for i in range(8):
        print(*m[i])
        
elif T==2: 
    for x in range(8):
        for y in range(8):
            m[x][y]=m[x][y]*q[x][y]
    MM = [[0]*8 for i in range(8)]
    
    for i,j in ls:
        SU = 0
        for u in range(8):
            sumv=0
            au = pow(1/2,1/2) if u==0 else 1
            for v in range(8):
                av = pow(1/2,1/2) if v==0 else 1
                sumv +=au*av*m[u][v]*math.cos(math.pi/8*(i+0.5)*u)*math.cos(math.pi*v*(j+1/2)/8)
            SU += sumv
        MM[i][j] = int(SU/4+128+0.5)
        if MM[i][j] > 255:
            MM[i][j] = 255
        elif MM[i][j] < 0:
            MM[i][j] = 0
    for i in range(8):
        print(*MM[i])
		
		


你可能感兴趣的:(python,算法,开发语言)