”十分“求助,只对#1

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

贪心过不了的,要用堆
by 时崎狂三老公 @ 2020-11-20 15:03:12


贪心还有 $ 10 $ 分,震惊!!
by Kacho @ 2021-01-08 20:45:21


堆AC代码: ```cpp #include<iostream> #include<cstdio> #include<queue> using namespace std; priority_queue<int,vector<int>,greater<int> > heap; int main(){ int n,ans=0; cin>>n; for(int i=1;i<=n;i++){ int s; cin>>s; heap.push(s); } for(int i=1;i<=n-1;i++){ int a=heap.top(); heap.pop(); int b=heap.top(); heap.pop(); ans+=(a+b); heap.push(a+b); } cout<<ans; } ```
by _melon @ 2021-03-26 06:22:47


|