奇奇怪怪的90分求助

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

用啥队列,用堆他不香吗? ```cpp #include<bits/stdc++.h> using namespace std; priority_queue<int,vector<int>,greater<int> >q; int n,x,y,z,ans=0; int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>x; q.push(x); } while(q.size()>=2) { y=q.top(); q.pop(); z=q.top(); q.pop(); ans+=y+z; q.push(y+z); } cout<<ans; } ```
by ㌠㌲㌳㌱㌴㌶ @ 2021-04-22 21:40:03


|