文章目录 小白入门赛 1-十二生肖 2-欢迎参加福建省大学生程序设计竞赛 3-匹配二元组的数量 4-元素交换 5-下棋的贝贝 6-方程 强者挑战赛 1-元素交换 2-下棋的贝贝 3-方程 4-学《博弈论》的贝贝 5-学《数论》的贝贝 6-学《树论》的贝贝
小白入门赛
N = int ( input ( ) )
lst = [ 0 ] + list ( map ( int , input ( ) . split( ) ) )
s = set ( )
for i in range ( 1 , N + 1 ) : s. add( i * lst[ i] )
print ( N - len ( s) )
N = int ( input ( ) )
lst = list ( map ( int , input ( ) . split( ) ) )
cnt = 0
for i in range ( 0 , N << 1 , 2 ) : if lst[ i] == 1 : cnt += 1
print ( min ( cnt, N - cnt) )
from math import sqrtn = int ( input ( ) )
L = int ( sqrt( n) )
ans = 4 * ( L - 2 ) * ( L - 2 ) + 4 * 3 * ( L - 2 ) + 4 * 2
diff = n - L * L
if diff > 0 and diff <= L: ans += 4 * diff - 2
elif diff > L: ans += 4 * diff - 4
print ( ans)
MOD = pow ( 10 , 9 ) + 7
def multiply ( arr1, arr2) : arr = [ [ 0 , 0 ] , [ 0 , 0 ] ] for i in range ( 2 ) : for j in range ( 2 ) : arr[ i] [ j] = arr1[ i] [ 0 ] * arr2[ 0 ] [ j] + arr1[ i] [ 1 ] * arr2[ 1 ] [ j] if arr[ i] [ j] >= MOD: arr[ i] [ j] %= MODreturn arrdef qpow ( Mat, n) : ans = [ [ 1 , 0 ] , [ 0 , 1 ] ] while n > 0 : if n & 1 == 1 : ans = multiply( ans, Mat) Mat = multiply( Mat, Mat) n >> = 1 return ansT = int ( input ( ) )
for _ in range ( T) : n, k = map ( int , input ( ) . split( ) ) temp = qpow( [ [ k, - 1 ] , [ 1 , 0 ] ] , n - 1 ) print ( ( temp[ 0 ] [ 0 ] * k + temp[ 0 ] [ 1 ] * 2 ) % MOD)
强者挑战赛
N = int ( input ( ) )
lst = list ( map ( int , input ( ) . split( ) ) )
cnt = 0
for i in range ( 0 , N << 1 , 2 ) : if lst[ i] == 1 : cnt += 1
print ( min ( cnt, N - cnt) )
from math import sqrtn = int ( input ( ) )
L = int ( sqrt( n) )
ans = 4 * ( L - 2 ) * ( L - 2 ) + 4 * 3 * ( L - 2 ) + 4 * 2
diff = n - L * L
if diff > 0 and diff <= L: ans += 4 * diff - 2
elif diff > L: ans += 4 * diff - 4
print ( ans)
MOD = pow ( 10 , 9 ) + 7
def multiply ( arr1, arr2) : arr = [ [ 0 , 0 ] , [ 0 , 0 ] ] for i in range ( 2 ) : for j in range ( 2 ) : arr[ i] [ j] = arr1[ i] [ 0 ] * arr2[ 0 ] [ j] + arr1[ i] [ 1 ] * arr2[ 1 ] [ j] if arr[ i] [ j] >= MOD: arr[ i] [ j] %= MODreturn arrdef qpow ( Mat, n) : ans = [ [ 1 , 0 ] , [ 0 , 1 ] ] while n > 0 : if n & 1 == 1 : ans = multiply( ans, Mat) Mat = multiply( Mat, Mat) n >> = 1 return ansT = int ( input ( ) )
for _ in range ( T) : n, k = map ( int , input ( ) . split( ) ) temp = qpow( [ [ k, - 1 ] , [ 1 , 0 ] ] , n - 1 ) print ( ( temp[ 0 ] [ 0 ] * k + temp[ 0 ] [ 1 ] * 2 ) % MOD)