二分
文章平均质量分 51
ZustinLau
I am currently studying Economics at the Chinese University of Hong Kong and I am interested in data structure and algorithms.
展开
-
1488. Avoid Flood in The City
1. We first use a multiset to store all the index of the sunny day2. We second store the lake in a map using the index as a value3. When we find a lake that already existed on the map, meaning that it would flood, we try to find the first sunny day after t原创 2022-06-22 17:39:25 · 175 阅读 · 0 评论 -
牛客算法課 (算法入門班) 二分, 三分, 01分數規劃
我們二分答案, 有多少套牌.然後如果二分出來的是 x套牌, 我們檢查, 組成x套牌需要用到多少張joker, 如果joker的數量超過x, 說明同一個組合裡用到了超過1張的joker. 我們還要檢查使用的joker 有沒有超過題目限定的m.給定每天有多少個教室可以借. 和. 每天有多少份訂單(包括借出和反還時間 和 數量).暴力思路, 直接遍歷每天的訂單 同時 修改每天可以借出的教室, 用 O(n * m * (t - s)),這個顯然會超時.由於我們知道, 如果某一個天所有教室都借出去了, 然後有人再借那原创 2022-06-28 10:13:28 · 411 阅读 · 0 评论 -
33. Search in Rotated Sorted Array && 33. Search in Rotated Sorted Array
rotated sorted array. there are two parts. both are sorted, our target either in left to mid, or mid to right.So, basically, we need to find the if the left hand side or right hand side are sorted.if(nums[l]原创 2022-06-14 18:38:15 · 63 阅读 · 0 评论 -
410. Split Array Largest Sum
可以在答案集上二分,枚舉不同的答案,然後查看是否可以分割成m塊。由於是求subarray,對於能否以某一和進行分割只需要花O(n)的時間,所以時間複雜度是 Nlog(sum)。int binarySearch(int sum, vector<int> nums, m){ int l = 0, r = sum; while(l <= r){ int mid = (l + r) /2; if(check(mid, nums, m))l =原创 2022-04-01 15:31:50 · 120 阅读 · 0 评论