左神基础班-切金条左神基础班-切金条

 

#include<iostream>
#include<queue>
using namespace std;
template<class T>
int getLength(T& arr);
int main(){

	priority_queue<int,vector<int>,greater<int> > small_heap;
	int arr[] = {3,4,1,2};
	int length = getLength(arr);
	int sum = 0;
	int i=0;
	int help =0;
	while(i<length){
		small_heap.push(arr[i]);
		i++;
	}
	while(small_heap.size() != 1){
		//出堆两次
		help += small_heap.top();
		small_heap.pop();
		help += small_heap.top();
		small_heap.pop();
		//计量损失,并放入新值
		sum += help;
		small_heap.push(help);
		help = 0;
	}
	cout << sum;
	return 0;
}
template<class T>
int getLength(T& arr){
	return sizeof(arr)/sizeof(arr[0]);
}

 

相关文章:

  • 2021-12-01
  • 2021-07-31
  • 2021-08-19
  • 2021-11-04
  • 2021-06-24
  • 2021-06-24
  • 2021-10-28
  • 2021-12-08
猜你喜欢
  • 2021-08-23
  • 2022-12-23
  • 2021-06-29
  • 2021-12-22
  • 2021-11-06
  • 2021-05-03
  • 2022-01-11
相关资源
相似解决方案