优秀python代码_优秀代码收集计划(python)

counter数组

bisect(lower_bound upper_bound)

列表推导式

Counter数组

https://codeforces.com/contest/1208/problem/B

import sys

input=sys.stdin.readline

n=int(input())

A=list(map(int,input().split()))

from collections import Counter

import copy

C=Counter(A)

for a in A:

if C[a]<=1:

del C[a]

if not(C):

print(0)

sys.exit()

ans=n-1

for i in range(n):

D=copy.deepcopy(C)

for j in range(i,n):

if D[A[j]]>1:

D[A[j]]-=1

if D[A[j]]==1:

del D[A[j]]

if not(D):

ans=min(ans,j-i+1)

break

print(ans)

bisect

import bisect

L = [1,3,3,3,6,8,12,15]

x = 3

x_insert_point = bisect.bisect_left(L,x)

print (x_insert_point)

x_insert_point = bisect.bisect_right(L,x)

print(x_insert_point)

列表推导式

# https://codeforces.com/contest/1332/problem/C

def f(l):

d={}

for i in l:

if i in d:

d[i]+=1

else:

d[i]=1

return len(l)-max(d.values())

import sys

for _ in range(int(sys.stdin.readline())):

n,k=map(int,sys.stdin.readline().split())

s=input()

print(sum(f(s[j::k]+s[k-j-1::k]) for j in range(k//2))+sum(f(s[k//2::k]) for j in range(k%2)))

进制转换

def toshi(x):

if ‘0‘<=x<=‘9‘:

return ord(x)-48

return ord(x)-ord(‘a‘)+10

def shito(x):

if 0<=x<=9:

return chr(x+48)

return chr(x-10+ord(‘a‘))

s=input()

a,b=map(int,input().split())

ans=0

for i in s:

ans*=a

ans+=toshi(i)

if ans==0:

print(0)

pr=‘‘

while ans>0:

pr=shito(ans%b)+pr

ans//=b

print(pr)

原文:https://www.cnblogs.com/reshuffle/p/12242314.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值