202206-1归一化处理
n=eval(input())
L=input().split()
L=[int(x) for x in L]
pinjun=sum(L)/len(L)
s=0
for ai in L:
s=s+(ai-pinjun)**2
fangcha=s/len(L)
for ai in L:
fai=(ai-pinjun)/fangcha**0.5
print(fai)
201312-1出现次数最多的数
n=eval(input())
L=list(map(int,input().split()))
A=[]
k=max(L)
cnt=[0]*(k+1)
for i in range(n):
if L[i] in A:
temp=L[i]
cnt[temp]+=1
else:
temp=L[i]
cnt[temp]=1
A.append(L[i])
M=max(cnt)
print(cnt.index(M))
201403-1相反数
N=eval(input())
L=list(map(int,input().split()))
cnt=0
for num in L:
if -num in L:
cnt+=1
print(int(cnt/2))
201409-1相邻数对
n=eval(input())
L=list(map(int,input().split()))
cnt=0
for i in range(n-1):
for j in range(i+1,n):
if abs(L[j]-L[i])==1:
cnt+=1
print(cnt)
201412-1门禁系统
n=eval(input())
L=list(map(int,input().split()))
M=[]
cnt=[0]*n
for i in L:
if i in M:
cnt[i]+=1
print(cnt[i],' ',end=' ')
else:
cnt[i]=1
print(cnt[i],' ',end=' ')
M.append(i)
201503-1图像旋转
n,m=map(int,input().split())
jz=[]
for i in range(n):
L=list(map(int,input().split()))
jz.insert(0,L)
for i in range(m):
for j in range(n):
print(jz[n-j-1][m-i-1],'',end='')
print(' ')
201509-1数列分段
n=eval(input())
L=list(map(int,input().split()))
cnt=1
for i in range(1,n):
if L[i]!=L[i-1]:
cnt+=1
print(cnt)
201512-1 数位之和
n=input()
s=0
for i in range(len(n)):
temp=int(n[i])
s=s+temp
print(s)
201604-1 折点计数
n=eval(input())
L=list(map(int,input().split()))
cnt=0
for i in range(1,n-1):
if (L[i-1]<L[i] and L[i+1]<L[i]) or (L[i-1]>L[i] and L[i+1]>L[i]):
cnt+=1
print(cnt)
201609-1最大波动
n=eval(input())
L=list(map(int,input().split()))
max=0
for i in range(1,n):
temp=abs(L[i]-L[i-1])
if temp>max:
max=temp
print(max)
201612-1 中间数
n=eval(input())
L=list(map(int,input().split()))
L.sort()
flag=0
for i in range(n):
big=0
small=0
for j in range(n):
if L[j]<L[i]:
small+=1
if L[j]>L[i]:
big+=1
if big==small:
print(L[i])
flag=1
break
if flag==0:
print(-1)
201703-1 分蛋糕
n,k=map(int,input().split())
L=list(map(int,input().split()))
sum=0
cnt=0
for i in range(n):
sum=sum+L[i]
if sum<k and i==n-1:
cnt+=1
if sum>=k:
cnt+=1
sum=0
print(cnt)
202006-1线性分类器
n,m=map(int,input().split())
N=[]
for i in range(n):
temp=input().split()
N.append(temp)
for i in range(m):
L1=[]
L2=[]
M=list(map(int,input().split()))
for j in N:
if M[0]+int(j[0])*M[1]+int(j[1])*M[2]>0:
L1.append(j[2])
if M[0]+int(j[0])*M[1]+int(j[1])*M[2]<0:
L2.append(j[2])
if ('A' in L1 and 'B' in L1) or ('A' in L2 and 'B' in L2):
print('No')
else:
print('Yes')
202109-1数组推导
n=int(input())
L=list(map(int,input().split()))
L1=[]
if len(set(L))==n:
print(sum(L))
print(sum(L))
else:
L1.append(L[0])
for i in range(1,n):
if L[i]!=L[i-1]:
L1.append(L[i])
else:
L1.append(0)
print(sum(L))
print(sum(L1))
201709-1打酱油
N=eval(input())
k1=N//50
k2=N%50//30
k3=N%50%30//10
print(k1*7+k2*4+k3)
201712-1最小差值
n=eval(input())
L=list(map(int,input().split()))
MIN=abs(L[1]-L[0])
for i in range(n-1):
for j in range(i+1,n):
m=abs(L[j]-L[i])
if m<MIN:
MIN=m
print(MIN)
201803-1跳一跳
L=list(map(int,input().split()))
sum=0
flag=1
for i in range(len(L)):
if L[i]==2:
sum=sum+2*flag
flag+=1
else:
flag=1
sum+=L[i]
print(sum)
201809-1卖菜
n=eval(input())
K=[]
L=list(map(int,input().split()))
for i in range(n):
if i==0:
ave=(L[i]+L[i+1])//2
K.append(ave)
elif i==(n-1):
ave=(L[i]+L[i-1])//2
K.append(ave)
else:
ave=(L[i]+L[i+1]+L[i-1])//3
K.append(ave)
for k in K:
print(k,end=' ')
201812-1小明上学
r,y,g=map(int,input().split())
n=eval(input())
L=[]
sum=0
for i in range(n):
temp=list(map(int,input().split()))
L.append(temp)
for i in range(n):
if L[i][0]==0:
sum=sum+L[i][1]
if L[i][0]==1:
sum=sum+L[i][1]
if L[i][0]==2:
sum=sum+L[i][1]+r
print(sum)
201903-1小中大
n=eval(input())
L=list(map(int,input().split()))
L1=[]
L1.append(max(L))
if n%2!=0:
L1.append(L[n//2])
else:
if (L[n//2-1]+L[n//2])%2==0:
L1.append((L[n//2-1]+L[n//2])//2)
else:
L1.append('%.1f'%((L[n//2-1]+L[n//2])/2))
L1.append(min(L))
for i in L1:
print(i,end=' ')
202203-1未初始化警告
n,k=map(int,input().split())
num=[[i for i in map(int,input().split())] for j in range(k)]
time=0
temp=set()
for i in range(k):
if num[i][1]!=0 and num[i][1] not in temp:
time+=1
temp.add(num[i][0])
print(time)
201909-1小明种苹果
N,M=map(int,input().split())
L=[]
T=[]
s=0
for i in range(N):
temp=list(map(int,input().split()))
L.append(temp)
for i in range(N):
s=s+sum(L[i])
t=sum(L[i])-L[i][0]
T.append(t)
MIN=min(T)
print(s,end=' ')
print(T.index(MIN)+1,end=' ')
print(-MIN)
202112-1序列查询
n,N=map(int,input().split())
L=list(map(int,input().split()))
L.insert(0,0)
F=[]
sum=0
num=0
for i in range(len(L)):
if i==len(L)-1:
for j in range(N-L[-1]):
F.append(num)
else:
for j in range(L[i+1]-L[i]):
F.append(num)
num+=1
for i in range(n):
sum=sum+F[L[i]]*(L[i+1]-L[i])
sum=sum+F[L[n]]*(N-L[n])
print(sum)
201912-1报数
n=eval(input())
cnt=1
c=1
num1=0
num2=0
num3=0
num4=0
while cnt<=n:
if c%7==0 or '7' in str(c):
if c%4==1:
num1+=1
if c%4==2:
num2+=1
if c%4==3:
num3+=1
if c%4==0:
num4+=1
else:
cnt+=1
c+=1
print(num1)
print(num2)
print(num3)
print(num4)
202104-1灰度直方图
n,m,l=map(int,input().split())
A=[[i for i in map(int,input().split())] for j in range(n)]
L=[0]*l
for i in range(n):
for j in range(m):
L[A[i][j]]+=1
for i in range(l):
print(L[i],end=' ')
202012-1期末预测之安全指数
n=eval(input())
L=[[i for i in map(int,input().split())] for j in range(n)]
sum=0
for i in range(n):
sum=sum+L[i][0]*L[i][1]
if sum<=0:
print(0)
else:
print(sum)
202009-1称检测点查询
n,X,Y=map(int,input().split())
S=[]
for i in range(1,n+1):
x,y=map(int,input().split())
s=((X-x)**2+(Y-y)**2)
S.append([s,i])
S.sort(key=lambda x:x[0])
print(S[0][1])
print(S[1][1])
print(S[2][1])
|