用的规律求的和,只过了第一个点

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

为什么不用堆来维护呢? ``` #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; priority_queue<int,vector<int>,greater<int>> heap; while(n--){ int x; cin>>x; heap.push(x); } int res=0; while(heap.size()>1){ int a=heap.top(); heap.pop(); int b=heap.top(); heap.pop(); res=res+a+b; heap.push(a+b); } cout<<res; } ```
by Wiales_Pretharp @ 2022-03-11 11:02:15


您确定您的规律是对的吗(?)
by chenzida @ 2022-03-11 11:28:47


|