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 段,已知每段长度。切割木条费用是所切木条长度。求最小切割总费用。
#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 段,已知每段长度。切割木条费用是所切木条长度。求最小切割总费用。
相关文章推荐
- POJ—3253—Fence Repair—【贪心】【优先队列】
- POJ 3253 Fence Repair STL 优先队列
- Fence Repair POJ 3253
- 贪心法-Fence Repair POJ - 3253
- 【原创】【合并类贪心】POJ 3253 1862 2709; Fence Repair && Stripies && Painter
- poj 3253 Fence Repair greater<int>
- Fence Repair POJ - 3253 最小优先队列,哈弗曼树
- Fence Repair POJ - 3253
- POJ 3253 Fence Repair Huffman
- poj-3253 Fence Repair **
- POJ 3253 Fence Repair C++ STL multiset 可解
- 贪心法 Fence Repair POJ 3253 霍夫曼(Huffman)编码原理 acmclub 12326
- Fence Repair POJ - 3253
- 刷题——Fence Repair POJ - 3253
- Fence Repair POJ - 3253 (贪心!!哈夫曼最小二叉树)
- POJ Fence Repair(优先队列)
- 区间DP与贪心算法的联系(uav Cutting Sticks && poj Fence Repair(堆的手工实现))
- poj Fence Repair 贪心
- POJ Fence Repair-哈夫曼树思想
- 区间DP与贪心算法的联系(uav Cutting Sticks && poj Fence Repair(堆的手工实现))