1 条题解
-
0
在数据范围小的情况下可以使用优先队列来实现 (其实本质上就是一个堆) 数据范围大的话建议手写堆 可以试一下加强版:https://www.luogu.com.cn/problem/P6033
#include <bits/stdc++.h> using namespace std; int main() { priority_queue<int,vector<int>,greater<int> > q; int n; int ans = 0; cin >> n; while(n--) { int x; cin >> x; q.push(x); } while(q.size()>=2) { int a = q.top(); q.pop(); int b = q.top(); q.pop(); ans+=(a+b); q.push(a+b); } cout << ans; return 0; }
- 1
信息
- ID
- 250
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- 8
- 标签
- 递交数
- 11
- 已通过
- 8
- 上传者