n=int(input()) s=input() res=0 for i in range(len(s)): if i==len(s)//2: break if s[i]!=s[-1-i]: res+=1 print(res)
2.求最小的公因数 ,python暴力过了 80%
l=int(input()) for _ in range(l): m,n=map(int,input().split()) if m==1 and n==1: print(1) continue for i in range(2,int(1e8+5)): if m*n%i==0: print(i) break
3.数据太水,暴力AC
n=input() a=list(map(int,input().split())) res=1e9+10 t=0 for i in range(len(a)): t|=a[i] res=1e9+10 for i in range(len(a)): now=0 for j in range(i,len(a)): now|=a[j] if now==t: res=min(res,j-i+1) break print(res)
4.感觉自己思路是对的,实际AC 0.2,求大佬指点代码。
def q(n): if n<=0: return 1 return n*q(n-1) if n!=1 else 1 def f(j,i): if i==0&nbs***bsp;j==0: return 1 return q(j)//(q(i)*q(j-i)) if i!=j else 1 n,m=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): v,b,c,x=map(int,input().split()) tt=f(c,x) g[v-1].append((b-1,tt)) g[b-1].append((v-1,tt)) res=-1 def dfs(now,s,p,b): global res if p==(1<<n)-1: for k,l in g[now]: if k==b: res=max(res,s+l) return for x,val in g[now]: if (1<<x)&p!=0: continue dfs(x,s+val,p|(1<<x),b) for i in range(n): dfs(i,0,0|(1<<i),b) print(res if res==-1 else res%(10**9+7))
全部评论
(1) 回帖