第一题
输入描述
输出描述
输入例子
输出例子
2
3
解题代码
from bisect import bisect_left
T = int(input())
for _ in range(T):
n = int(input())
X = map(int, input().split())
Y = map(int, input().split())
a = sorted(zip(X, Y), key=lambda x: (x[0], -x[1]))
total = 0
q = [0] * 100005
for i in range(n):
t = bisect_left(a=q, x=a[i][1], lo=0, hi=total)
if t == total:
total += 1
q[t] = a[i][1]
print(total)
第二题
输入描述
输出描述
输入例子
输出例子
解题代码
MOD = int(1e9+7)
def two_num_pow_sum(a, b, n):
if n == 1:
return a
matrix=[[a, -b], [1, 0]]
res = matrix_pow(matrix, n - 1)
return (res[0][0] * a + res[0][1] * 2 ) % MOD
def matrix_pow(matrix, n):
ans = [[1, 0], [0, 1]]
while n > 0:
if n & 1 != 0:
ans = matrix_mul(ans, matrix)
n >>= 1
matrix = matrix_mul(matrix, matrix)
return ans
def matrix_mul(ma, mb):
ans = [[0] * 2 for _ in range(2)]
for i in range(2):
for j in range(2):
ans[i][j] = ma[i][0] * mb[0][j] + ma[i][1] * mb[1][j]
if ans[i][j]>=0:
ans[i][j] %= MOD
else:
ans[i][j] = - (abs(ans[i][j]) % MOD)
return ans
while True:
try:
t = int(input())
ans = []
for i in range(t):
a, b, n = list(map(int, input().split()))
ans.append(two_num_pow_sum(a, b, n))
for num in ans:
print(num)
except:
break