当前位置:首页 > 编程笔记 > 正文
已解决

7-4 修理牧场 分数 15

来自网友在路上 177877提问 提问时间:2023-11-05 03:10:40阅读次数: 77

最佳答案 问答题库778位专家为你答疑解惑

在这里插入图片描述

在这里插入图片描述

#include<iostream>
#include<queue>
using namespace std;
#define maxn 10005int main()
{int n = 0, data = 0;cin >> n;//建小堆: //上调建堆中用greater: 父大子小 父子交换 小的上去 大的下去 priority_queue<int, vector<int>, greater<int>> pq;for (int i = 0; i < n; i++){cin >> data;pq.push(data);}long long money = 0;while (!pq.empty()){int top1 = pq.top();pq.pop();if (pq.empty())break;int top2 = pq.top();pq.pop();int coin = top1 + top2;pq.push(coin);money += coin;}cout << money;return 0;
}
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"7-4 修理牧场 分数 15":http://eshow365.cn/6-32344-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!