合并果子这道题首先是建立在优先队列的基础上的。
所以:
1.下次排版弄好一点。
2.先把优先队列学会了(pop,push,top,pri...)在做这道题吧。
3.你是根据样例猜的这么做吗,你这程序连样例都过不了。
by 角边边证全等 @ 2018-02-10 15:44:16
@[nI、唯一](/space/show?uid=73575)
by 角边边证全等 @ 2018-02-10 15:48:20
老师要求做的
by nI、唯一 @ 2018-02-10 15:51:58
现在在上课,必须做完,大佬帮忙
by nI、唯一 @ 2018-02-10 15:52:38
@[wish_a_dream](/space/show?uid=40972)
by nI、唯一 @ 2018-02-10 15:52:48
用优先队列做啊
by zsc2003 @ 2018-02-10 15:53:12
我把程序给你吧,要理解性的去做
by 角边边证全等 @ 2018-02-10 15:53:23
```cpp
// luogu-judger-enable-o2
#include<queue>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
priority_queue<int,vector <int>,greater<int> > q;
int n,i,a,b,x,sum=0;
cin>>n;
for(i=0;i<n;i++){
cin>>x;
q.push(x);
}
for(i=1;i<n;i++){
a=q.top();
q.pop();
b=q.top();
q.pop();
q.push(a+b);
sum+=a+b;
}
cout<<sum;
return 0;
}
```
by 角边边证全等 @ 2018-02-10 15:53:48
@[nI、唯一](/space/show?uid=73575)
by 角边边证全等 @ 2018-02-10 15:54:17
@[wish_a_dream](/space/show?uid=40972) 小弟甘拜下风
by nI、唯一 @ 2018-02-10 16:04:55