m =int(input())n =list(map(int, input().split()))n_sum =sum(n)n_len =len(n)n_avg = n_sum // n_lenif n_sum / n_len != n_avg:print(-1)ret =0for i in n:if i > n_avg: ret += i - n_avgprint(ret //2)
Python(AC)
m =int(input())n =list(map(int, input().split()))deffoo(n): n_sum =sum(n) n_len =len(n) n_avg = n_sum // n_lenif n_sum / n_len != n_avg:return-1 odd =0 eve =0for i in n:if i %2==1: odd =1# 存在奇数if i %2==0: eve =1# 存在偶数if n_avg %2==1and eve:return-1if n_avg %2==0and odd:return-1 ret =0for i in n:if i > n_avg: ret += i - n_avgreturn ret //2print(foo(n))
多少个狗
思路
斐波那契数列
Python(AC)
n =int(input())dp = [1,1]for i inrange(2, n): dp.append(dp[i-1] + dp[i-2])print(dp[n-1])