poj 3253 Fence Repair 哈夫曼最优解STL解法
2014-01-07 19:06
337 查看
用STL模拟就够了
#include<iostream> #include<cmath> #include<cstdio> #include<sstream> #include<cstdlib> #include<string> #include<string.h> #include<cstring> #include<algorithm> #include<vector> #include<map> #include<set> #include<stack> #include<iterator> #include<queue> #include<ctime> #include<bitset> #define eps 1e-6 #define INF 0x3f3f3f3f #define PI acos(-1.0) //#define ll __int64 #define ll long long #define lson l,m,(rt<<1) #define rson m+1,r,(rt<<1)|1 #define M 1000000007 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; int a[20005]; multiset<int> s; multiset<int>::iterator it1; multiset<int>::iterator it2; int main() { int n; while(~scanf("%d",&n)) { long long ans=0; s.clear(); for(int i=0;i<n;i++) { scanf("%d",&a[i]); s.insert(a[i]); } int tmp; if(n==1) {puts("0");continue;} while(n!=1) { it1=it2=s.begin(); it2++; ans+=(*it1)+(*(it2)); tmp=(*it1)+(*it2); s.erase(it1); s.erase(it2); s.insert(tmp); n--; } cout<<ans<<endl; } return 0; }
相关文章推荐
- 文章标题 POJ 3253 : Fence Repair(哈夫曼)
- POJ-3253--Fence Repair(简单哈夫曼的应用)
- POJ 3253 Fence Repair(哈夫曼)
- POJ 3253 Fence Repair(哈夫曼)
- POJ 3253 fence Repair 一个很有趣的贪心解法
- POJ 3253 fence repair [STL][priority_queue]
- poj3253——Fence Repair(哈夫曼)
- poj 3253 Fence Repair(哈夫曼+二叉堆)
- 贪心+优先队列(哈夫曼思想)POJ 3253 Fence Repair
- POJ-5353-Fence Repair(哈夫曼问题->贪心(一种解法两种做法))
- poj 3253 Fence Repair(哈夫曼)
- poj 3253 Fence Repair之优先队列解法
- poj-3253-Fence Repair(哈夫曼)
- poj 3253 Fence Repair 数据结构(哈夫曼数)
- poj 3253 Fence Repair (STL优先队列)
- poj 3253 Fence Repair (哈夫曼)
- POJ 3253 Fence Repair(STL之优先队列)
- Poj-3253-Fence Repair ( 哈夫曼
- POJ 3253 Fence Repair (哈夫曼)
- POJ 3253 Fence Repair(小顶堆的应用)