题目:将数组和减半的最少操作
贪心思路:每次挑选最大的数来减半。
解法:贪心+大根堆
class Solution {
public:int halveArray(vector<int>& nums) {priority_queue<double> heap;double sum =0.0;for(int& x : nums){heap.push(x);sum += x;}sum /= 2.0;int count = 0;while(sum > 0){double t = heap.top()/2.0;heap.pop();sum -= t;count++;heap.push(t);}return count;}
};