字节跳动笔试
第一题:
import sys if __name__ == "__main__": n = int(sys.stdin.readline().strip()) nums = [] for i in range(n): line = sys.stdin.readline().strip() val = list(map(int, line.split())) t = (val[0], val[1]) nums.append(t) nums.sort() x = int(sys.stdin.readline().strip()) times = '' if x < 60: times = (0, x) else: times = (1, x - 60) line = sys.stdin.readline().strip() val = list(map(int, line.split())) end = (val[0], val[1]) # 上课时间 flag = True for i in range(n - 1, -1, -1): if nums[i][0] + times[0] <= end[0] and nums[i][1] + times[1] <= end[1]: s = str(nums[i][0]) + ' ' + str(nums[i][1]) print(s.strip()) flag = False break if flag: s = str(nums[0][0]) + ' ' + str(nums[0][1]) print(s.strip())
第三题:
import sys if __name__ == '__main__': n = int(sys.stdin.readline().strip()) nums = list(map(int, sys.stdin.readline().strip().split())) ans = [100] * n for i in range(n - 2, -1, -1): if nums[i] > nums[i + 1]: ans[i] = ans[i + 1] + 100 for i in range(1, n): if nums[i - 1] < nums[i]: ans[i] = max(ans[i - 1] + 100, ans[i]) # print(ans) print(sum(ans))