POJ 1251
来源:互联网 发布:apache ant linux 编辑:程序博客网 时间:2024/05/21 10:55
这道题就是对优先队列的应用。
huffman+priority_queue
#include <vector>#include <queue>#include <string>#include <algorithm>#include <string.h>#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;int main(){ string in; int count[200]; //count the character while(cin>>in&&in!="END"){ memset(count,0,sizeof(count)); for(int i=0;i<in.length();i++){ count[in[i]]++; } //the priority queue priority_queue<int,vector<int>,greater<int> >que; for(int i=0;i<200;i++){ if(count[i]!=0){ que.push(count[i]); } } int len=in.length(),sum=0; while(que.size()>1){ int a=que.top();que.pop(); int b=que.top();que.pop(); sum+=(a+b); que.push(a+b); } if(sum==0){//sum==0 means just one character sum=len; } printf("%d %d %.1f\n",8*len,sum,double(8*len)/sum); //clear the que while(!que.empty()) que.pop(); } return 0;}
0 0
- poj 1251
- POJ 1251
- poj 1251
- poj-1251
- poj 1251
- poj 1251
- POJ 1251
- poj 1251
- POJ 1251
- poj-1251
- poj 1251
- POJ 1251
- POJ 1251
- POJ 1251 Jungle Roads
- poj 1251 Jungle Roads
- poj 1251 Prim算法
- poj 1251 Jungle Roads
- POJ-1251 jungle roads
- HDU 1669 Monkey and Banana
- Linux Netfilter实现机制和扩展技术
- 由Maven管理jar文件找不到而引出的问题java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRunt
- centos7安装docker
- Dubbo注册中心
- POJ 1251
- ZOJ-1610 Count the Colors
- 单链表实现多项式的相乘-c语言
- 线段树--按点建树
- The type org.junit.runners.BlockJUnit4ClassRunner cannot be resolved. It is indirectly referenced fr
- web前端之HTML5压缩图片compress image with canvas
- 视图添加移动手势
- Alamofire上传图片解决绑定参数问题
- FFprobe使用指南