C++10分。

P1090 [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G

思路是不是有一点问题。 不是用优先队列做的吗
by Lightning_Creeper @ 2023-06-29 12:48:51


```cpp #include<bits/stdc++.h> using namespace std; priority_queue<int, vector<int>,greater<int> >q; int n,x,ans; int main() { cin>>n; for(int i=1;i<=n;i++) cin>>x,q.push(x); while(q.size()>1){ int a=q.top(); q.pop(); int b=q.top(); q.pop(); ans+=a+b; q.push(a+b); } cout<<ans; return 0; }
by Libingyue2011 @ 2023-06-29 13:03:58


|