第一行一个正整数N。 接下来N行。每行两个整数分别表示X 和 H X1 H1 X2 H2 … XN HN输入限制: 对于70%的数据:0<N<10^40<Xi<10^60<Hi<10^6100%的数据:0<N<10^60<Xi<10^60<Hi<10^6
一个整数,表示最多可以卖出的宝物数
4 3 2 1 1 1 3 1 2
3
def binaysearch(nums,left,right,val): while left < right: mid = (left + right) // 2 if nums[mid] >= val: right = mid elif nums[mid] < val: left = mid + 1 return left def ans(nums,num): nums = sorted(nums,key = lambda x:(x[0],x[1])) temp = [0]*num for i in range(num): temp[i] = nums[i][1] res = [] for i in range(num): if res == []&nbs***bsp;res[-1] < temp[i]: res.append(temp[i]) else: idx = binaysearch(res, 0, len(res), temp[i]) res[idx] = temp[i] return len(res) if __name__ == "__main__": num = int(input()) #宝物的数量 nums = [] for i in range(num): nums.append(list(map(int,input().split()))) print(ans(nums,num))
input: [[32],[11],[13],[12]] sorted(input):[[11],[12],[13],[32]]
def binary_search(nums,left,right,val): mid = 0 while left < right: mid = (left+right) // 2 if val > nums[mid]: left = mid +1 else: right = mid return left def LIS(N,prices): res = [] for i in range(N): if not res or prices[i] > res[-1]: res.append(prices[i]) else: idx = binary_search(res, 0, len(res), prices[i]) res[idx] = prices[i] return len(res) def main(): N = int(input()) prices = [] for i in range(N): prices.append(list(map(int,input().split()))) prices.sort() h = [a[1] for a in prices] return LIS(N,h) print(main())