您的位置:首页 > Web前端

POJ 3253 Fence Repair G++

2017-09-22 10:12 274 查看
#include <queue>
#include <iostream>
//挑战 例题 2.4.2 抄书
using namespace std;
int main()
{
priority_queue<int,vector<int>,greater<int> > a;//min_heap 重要
int NUM;
cin>>NUM;
for(int i=0;i<NUM;i++)
{
int t;
cin>>t;
a.push(t);
}
long long ans=0;//重要
while(a.size()>1)//重要
{
int x,y;
x=a.top();
a.pop();
y=a.top();
a.pop();
int z;
z=x+y;
ans+=z;
a.push(z);
}
cout<<ans<<endl;
return 0;
}






一段木条,切成 n 段,已知每段长度。切割木条费用是所切木条长度。求最小切割总费用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: