t =list(input().strip().s plit())
data =list(map(int,input().split()))
n, i =int(t[0]),float(t[1])
res =0for x inrange(len(data)):
res += data[x]*(1+ i)**(-x)print("{:.3f}".format(res))
n, m =map(int,input().split())
early =[0]*(m +1)# 记录最早完成时间
late =[0]*(m +1)# 记录最晚完成时间
flag =1
p =[0]+list(map(int,input().split()))# 输入是否有依赖的科目,下标从1开始,第0位补0
t =[0]+list(map(int,input().split()))# 输入训练某科目需要花费的时间for i inrange(1, m +1):if p[i]==0:# 判断受有依赖的科目,如果为0,说明没有依赖的科目,直接从第1天开始
early[i]=1else:# 如果有依赖的科目,则该科目最早开始的时间为被依赖科目的最早开始时间+训练需要花费时间
early[i]= early[p[i]]+ t[p[i]]# 如果最早开始时间训练完成后大于n,则没有最晚开始时间if early[i]+ t[i]-1> n:
flag =0print(' '.join(map(str, early[1: m +1])))if flag ==1:for i inrange(m,0,-1):
temp =366# 寻找第i科目是否有被依赖的科目for j inrange(i +1, m +1):if p[j]== i:
temp =min(temp, late[j])# 如果没有被依赖,则等于n-消耗时间+1if temp ==366:
late[i]= n - t[i]+1else:
late[i]= temp - t[i]print(' '.join(map(str, late[1: m +1])))
JPEG解码(202212-3)
这道题自己在本地可以过,但是提交到平台上就运行错误,不太清楚是哪里错了
import math
Q =[[0for j inrange(8)]for i inrange(8)]
M =[[0for j inrange(8)]for i inrange(8)]# 扫描矩阵初始化
M_1 =[[0for j inrange(8)]for i inrange(8)]# 矩阵M与量化矩阵相乘后的结果
M_2 =[[0for j inrange(8)]for i inrange(8)]# 经过离散变换后的矩阵
M_3 =[[0for j inrange(8)]for i inrange(8)]# 经过加128取整后的矩阵# 离散余弦逆变换函数defdiscrete_cos_fun(x, y):
m =0for u inrange(8):
temp =0for v inrange(8):if u ==0:if v ==0:
temp += u1 * v1 * M_1[u][v]* math.cos((math.pi /8)*(x +0.5)* u)* math.cos((math.pi /8)*(y +0.5)* v)*0.25else:
temp += u1 * v2 * M_1[u][v]* math.cos((math.pi /8)*(x +0.5)* u)* math.cos((math.pi /8)*(y +0.5)* v)*0.25else:if v ==0:
temp += u2 * v1 * M_1[u][v]* math.cos((math.pi /8)*(x +0.5)* u)* math.cos((math.pi /8)*(y +0.5)* v)*0.25else:
temp += u2 * v2 * M_1[u][v]* math.cos((math.pi /8)*(x +0.5)* u)* math.cos((math.pi /8)*(y +0.5)* v)*0.25
m += temp
m =round(m,2)return m
# 取整函数:defturn(x):
x =round(x +128)if x <0:
x =0if x >255:
x =255return x
# 输出函数defprint_result(P):for x inrange(8):for y inrange(8):print(P[x][y], end =' ')print()# 输入量化矩阵for x inrange(8):
Q[x]=list(map(int,input().split()))# 输入扫描数据的个数
n =int(input())# 数字T = 0, 1, 2# 0:输出填充后的图像矩阵# 1:输出量化后的图像矩阵# 2:输出最终的解码结果
T =int(input())# 输入扫描数据
t =list(map(int,input().split()))#print(t)
i, j =0,0# 扫描矩阵每次扫描数据的位置
direction =2# 扫描矩阵每次的方向,1为左下,2为右上for x inrange(n):# 将数据赋值给扫描矩阵if i >=0and i < n and j >=0and j < n:
M[i][j]= t[x]#移动扫描矩阵位置:if direction ==1:
i +=1
j -=1if direction ==2:
i -=1
j +=1# 规则1:if i <0:
i =0
direction =1# 规则2:if j <0:
j =0
direction =2# 将矩阵M与量化矩阵相乘for x inrange(8):for y inrange(8):
M_1[x][y]= M[x][y]* Q[x][y]# 对矩阵进行离散余弦逆变换
u1, u2 = math.pow(0.5,0.5),1
v1, v2 = math.pow(0.5,0.5),1for x inrange(8):for y inrange(8):
M_2[x][y]= discrete_cos_fun(x, y)# 将矩阵的每个元素都加上128for x inrange(8):for y inrange(8):
M_3[x][y]= turn(M_2[x][y])#print_result(M_2)if T ==0:
print_result(M)if T ==1:
print_result(M_1)if T ==2:
print_result(M_3)
如此编码(202209-1)
n, m =map(int,input().split())
a =[0]+list(map(int,input().split()))
c =[0]*(n +1)# 前缀乘积数组
c[0]=1for i inrange(1, n +1):
c[i]= c[i -1]* a[i]
b =[0]*(n +1)# 正确答案的数组
temp=[0]*(n +1)# 存放m % ci的结果for i inrange(1, n +1):
temp[i]= m % c[i]for i inrange(1, n +1):
b[i]=(temp[i]- temp[i -1])// c[i -1]for i inrange(1, n +1):print(b[i], end =' ')
何以包邮(202209-2)
n, x =map(int,input().split())# 图书数量和包邮条件
f =[0]*(n * x)# 存储花费
a =[0]*( n +1)# 存储每个数的价格 # 进行遍历,将每本书的价格依次存入afor i inrange(1, n +1):
a[i]=int(input())
pre =sum(a)#满足m >= x的最小花费,初始值设置为总和for i inrange(1, n +1):for j inrange(pre,a[i]-1,-1):
f[j]=max(f[j], f[j - a[i]]+ a[i])for i inrange(x, pre +1):if f[i]>= x:print(f[i])break
归一化处理(202206-1)
import math
defturn_D(a,average):
res =0for i inrange(len(a)):
res += math.pow(a[i]- average,2)
res /=len(a)return res
defturn_f(a,average,d):
res =0
d = math.sqrt(d)
res =(a - average)/ d
return res
n =int(input())
a =list(map(int,input().split()))
average =sum(a)/ n
d = turn_D(a, average)for i inrange(n):
res = turn_f(a[i], average, d)print(res)
寻宝!大冒险!(202206-2)
# 树的棵数、绿化图和藏宝图的大小
n, l, s =map(int,input().split())# 以集合的形式存储树的坐标
points ={}for i inrange(n):
x, y =map(int,input().split())
points.update({(x,y):1})# 建立藏宝图
value =[]for i inrange(s+1):
value.insert(0,list(map(int,input().split())))# res值来记录绿化图中有多少处坐标可以与藏宝图左下角对应
res =0# 开始遍历树的坐标与藏宝图中的树的坐标进行比对for x, y in points:# 设置一个标志值来判定是否符合藏宝图要求
flag =0# 开始遍历比对for i inrange(s +1):for j inrange(s +1):if(x + i > l)or(y + j > l):
flag =1breakif value[i][j]:if(x + i, y + j)notin points:
flag =1breakelse:if(x + i, y + j)in points:
flag =1breakif flag ==1:breakif flag ==0:
res +=1print(res)
未初始化警告(202203-1)
版本1
N =int(1e5)+10
flag =[False]* N
n, k =map(int,input().split())
res =0for i inrange(k):
x, y =map(int,input().split())ifnot flag[y]and y !=0ornot flag[x]and x == y:
res +=1
flag[x]=Trueprint(res)
版本2(这个纯暴力,然后超时了,只得一半分)
##l, r = [], []##n, k = map(int, input().split())##for i in range(k):## x, y = map(int, input().split())## l.append(x)## r.append(y)##res = 0##for i in range(k):## if r[i] not in l[:i] and r[i] != 0:## res += 1####print(res)
出行计划(202203-2)
70分题解
defquery(q,plan):
cnt =0for i in plan:if i[0]< q + i[1]+ k and i[0]>= q + k:
cnt +=1return cnt
# 出行计划数目、查询个数、等待核酸检测结果所需时间
n, m, k =map(int,input().split())# 每项出行计划
plan =set()for i inrange(n):
tmp =tuple(map(int,input().split()))
plan.add(tmp)for i inrange(m):
q =int(input())print(query(q,plan))
满分题解
N =int(2e5)+10
diff =[0]* N
# 出行计划数目、查询个数、等待核酸检测结果所需时间
n, m, k =map(int,input().split())for i inrange(n):
t, c =map(int,input().split())# 在[l, r] 时间段内做核酸,则t时刻可进入
l =max(t - k - c +1,0)
r =max(t - k,0)# 在[l, r]时间段内能出行的计划的个数+1
diff[l]+=1
diff[r +1]-=1# 利用差分计算每个时间能出行个数for i inrange(1, N):
diff[i]+= diff[i -1]for j inrange(m):
q =int(input())
res = diff[q]print(res)
序列查询(202112-1)
#两个正整数n, N,分别代表n件商品,N代表最大预算
n, N =map(int,input().split())#输入n 个用空格分隔的整数 A1,A2,⋯,An
a =list(map(int,input().split()))
a.insert(0,0)
res =0for i inrange(2,len(a)):
res +=(a[i]- a[i -1])*(i -1)if N > a[n -1]:
res +=(N - a[n])* n
print(res)
序列查询新解(202112-2)
n, N =map(int,input().split())
a =[0]+list(map(int,input().split()))
r = N //(n +1)
g, f =[0]* N,[0]* N
for i inrange(1, n):# 对f(x)进行赋值
f[a[i]: a[i -1]]=[i]*(a[i +1]- a[i])if N > a[n -1]:
f[a[n]: N]=[n]*(N - a[n])# 计算g(x)for i inrange(N):
g[i]= i // r
error =0for i inrange(N):
error +=abs(g[i]- f[i])print(error)
数组推导(202109-1)
n =int(input())
b =list(map(int,input().split()))
max_res =sum(b)
s =set(b)
min_res =sum(s)print(max_res)print(min_res)
非零段划分(202209-2)
# 差分数组加前缀和
M =int(1e4)+5
b =[0]* M
n =int(input())
a =list(map(int,input().split()))
a.insert(0,0)for i inrange(1, n +1):# a[i - 1]到 a[i] - 1段的p都能构成新的非零段if a[i]> a[i -1]:# 处理差分数组以实现区间整体+1
b[a[i]]-=1
b[a[i -1]]+=1
ans =0for i inrange(1, M):
b[i]+= b[i -1]
ans =max(b[i], ans)print(ans)
灰度直方图(202104-1)
n, m, l =map(int,input().split())
a =[]
h =[0]* l
for i inrange(n):
a.extend(list(map(int,input().split())))for i inrange(l):
h[i]= a.count(i)print(' '.join(map(str, h)))
邻域均值(202204-2)
# 像素个数,灰度值范围, 邻域范围, 阈值
n, l, r, t =map(int,input().split())# 输入矩阵
a =[0]# 前缀和矩阵
b =[[0for j inrange(n +1)]for i inrange(n +1)]for i inrange(n):
tmp =list(map(int,input().split()))
tmp.insert(0,0)
a.append(tmp)# 预处理前缀和for i inrange(1, n +1):for j inrange(1, n +1):
b[i][j]= b[i -1][j]+ b[i][j -1]- b[i -1][j -1]+ a[i][j]
res =0for i inrange(1, n +1):for j inrange(1, n +1):# 判断矩阵的边界:
x1 =max(i - r,1)
y1 =max(j - r,1)
x2 =min(i + r, n)
y2 =min(j + r, n)# 计算矩阵中点的个数
tt =(x2 - x1 +1)*(y2 - y1 +1)if b[x2][y2]- b[x2][y1 -1]- b[x1 -1][y2]+ b[x1 -1][y1 -1]<= tt * t:
res +=1print(res)
期末预测之安全指数(202012-1)
N =int(1e5)+10
score, w =[0]* N,[0]* N
n =int(input())for i inrange(n):
score[i], w[i]=map(int,input().split())
y =0for i inrange(n):
y += score[i]* w[i]
y =max(0, y)print(y)
期末预测之最佳阈值(202012-2)
60分题解
N =int(1e5)+10
y , result ,pre =[0]* N,[0]* N,[0]* N
m =int(input())for i inrange(m):
y[i], result[i]=map(int,input().split())
tmp =set(y[:m])
res , data =0,0defpredict(x, y):global pre
for i inrange(m):if y[i]< x:
pre[i]=0else:
pre[i]=1defsum_pre(pre, result):
val =0for i inrange(m):if pre[i]== result[i]:
val +=1return val
for i in tmp:
predict(i, y)if sum_pre(pre, result)>= res:
res = sum_pre(pre, result)
data = i
pre =[0]*(m +10)print(data)
称检测点查询(202009-1)
points =[0]
distance ={}
n, X, Y =map(int,input().split())for i inrange(n):
points.append(tuple(map(int,input().split())))
d =0for i inrange(1, n +1):
d =(X - points[i][0])**2+(Y - points[i][1])**2
distance[i]= d
a =sorted(distance.items(), key =lambda x: x[1])for i inrange(3):print(a[i][0])
风险人群筛查(202009-2)
points =[]
n, k, t, xl, yd, xr, yu =map(int,input().split())
res =[0]* n # 记录每个人是 未停留0 or 1次 or k次for i inrange(n):
points.append(list(map(int,input().split())))
cnt =0# 分有连续多少个坐标位于高风险区域内,for j inrange(0,2* t,2):if xl <= points[i][j]<= xr and yd <= points[i][j +1]<= yu:
cnt +=1
res[i]=1if cnt >= k:
res[i]= k
breakelse:
cnt =0print(n - res.count(0))print(res.count(k))
线性分类器(202006-1)
points =[]# n个点的信息
A_group , B_group=[],[]# 如果值< 0 ,存入A,否则存入B
q =[]# m个查询
n, m =map(int,input().split())for i inrange(n):
points.append(list(input().split()))for i inrange(m):
q.append(list(map(int,input().split())))for c, a, b in q:
A_group.clear()
B_group.clear()for x in points:if a *int(x[0])+ b *int(x[1])+ c <0:
A_group.append(x[2])else:
B_group.append(x[2])if'A'in A_group and'B'in A_group or'A'in B_group and'B'in B_group:print('No')continueelse:print('Yes')
稀疏向量(202006-2)
u ={}
v ={}
n, a, b =map(int,input().split())for i inrange(a):
x, y =map(int,input().split())
u.update({x : y})for i inrange(b):
x, y =map(int,input().split())
v.update({x : y})if a >= b:
res =0for i in u.keys():if i in v:
res += u[i]* v[i]else:continueelse:
res =0for i in v.keys():if i in u:
res += u[i]* v[i]print(res)
报数(201912-1)
n =int(input())
cnt =[0]*5
i =0
flag =0while1:
i +=1if i %4==1and(i %7==0or'7'instr(i)):
cnt[1]+=1elif i %4==2and(i %7==0or'7'instr(i)):
cnt[2]+=1elif i %4==3and(i %7==0or'7'instr(i)):
cnt[3]+=1elif i %4==0and(i %7==0or'7'instr(i)):
cnt[4]+=1else:
flag +=1if flag == n:breakfor i inrange(1,5):print(cnt[i])
回收站选址(201902-2)
dx1 =[0,0,1,-1]
dy1 =[1,-1,0,0]
dx2 =[-1,1,1,-1]
dy2 =[1,1,-1,-1]
points ={}
garbage ={}
res =[0]*5
n =int(input())for i inrange(n):
points.update({tuple(map(int,input().split())):1})for i in points:
flag =1for j inrange(4):
tmp1, tmp2 = i[0]- dx1[j], i[1]- dy1[j]if(tmp1, tmp2)notin points:
flag =0breakif flag ==1:
garbage.update({i :0})for i in garbage.keys():for j inrange(4):
tmp1, tmp2 = i[0]- dx2[j], i[1]- dy2[j]if(tmp1, tmp2)in points:
garbage[i]+=1for j in garbage.values():
res[j]+=1for i inrange(5):print(res[i])
小明种苹果(201909-1)
n, m =map(int,input().split())# 苹果树的棵树和疏果操作的轮数
cnt =[0]*(n +5)# 存储每棵树的疏果个数,其中cnt[0]代表未疏果之前苹果树上有苹果的个数
k , p =0,0# 存储最大疏果的下标,以及最疏果的数量for i inrange(1, n +1):
tmp =list(map(int,input().split()))
cnt[0]+= tmp[0]
cnt[i]=sum(tmp[1: m+1])
t = cnt[0]-abs(sum(cnt[1:]))# 最后一轮疏果操作后所有苹果树上上下的苹果树总数
x =min(cnt[1: n +1])# 最大疏果个数
k = cnt.index(x)
p =abs(cnt[k])print(t,' ', k,' ', p)