poj 3253 Fence Repair 哈夫曼最优解STL解法
来源:互联网 发布:java二级考试 编辑:程序博客网 时间:2024/05/22 04:22
用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;}
5 0
- poj 3253 Fence Repair 哈夫曼最优解STL解法
- POJ 3253 Fence Repair C++ STL multiset 可解
- POJ 3253 fence repair [STL][priority_queue]
- POJ 3253 Fence Repair(哈夫曼)
- Poj-3253-Fence Repair ( 哈夫曼
- POJ 3253 fence Repair 一个很有趣的贪心解法
- poj 3253 Fence Repair之优先队列解法
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253Fence Repair
- POJ--3253 -- Fence Repair
- poj-3253-Fence Repair
- POJ 3253 Fence Repair
- Hadoop集群监测工具——ganglia安装实例
- 推荐13款JavaScript图形和图表绘制工具
- 姬松茸1
- html-keycode码大全
- scala在eclipse开发环境配置<转>
- poj 3253 Fence Repair 哈夫曼最优解STL解法
- Java 自动表单提交
- 0K6410学习之初步移植linux内核
- 姬松茸2
- ( PAT )1001. A+B Format (20)
- 姬松茸3
- Ubuntu下使用VLC的图形界面搭建一个RTSP服务器
- Hadoop Configuration设置自定义类变量
- 在文件上传时取完整的文件名