BZOJ 3253 Fence Repair 哈夫曼树 水题
http://poj.org/problem?id=3253
这道题约等于合并果子,但是通过这道题能够看出来哈夫曼树是什么了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<queue>
using namespace std;
#define LL long long
const int maxn=;
int n;
priority_queue< LL,vector<LL>,greater< LL > >q;
int main(){
while(~scanf("%d",&n)){
LL x,y;
for(int i=;i<=n;i++){scanf("%lld",&x);q.push(x);}
LL ans=;
while(!q.empty()){
x=q.top();q.pop();
if(q.empty())continue;
y=q.top();q.pop();
ans+=x+y;
q.push(x+y);
}
printf("%lld\n",ans);
while(!q.empty())q.pop();
}
return ;
}
BZOJ 3253 Fence Repair 哈夫曼树 水题的更多相关文章
- Poj 3253 Fence Repair(哈夫曼树)
Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...
- poj 3253 Fence Repair (哈夫曼树 优先队列)
题目:http://poj.org/problem?id=3253 没用long long wrong 了一次 #include <iostream> #include<cstdio ...
- POJ 3253 Fence Repair【哈弗曼树/贪心/优先队列】
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 53645 Accepted: 17670 De ...
- POJ 3253 Fence Repair(哈夫曼编码)
题目链接:http://poj.org/problem?id=3253 题目大意: 有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度 给定各个 ...
- POJ 3253 Fence Repair(简单哈弗曼树_水过)
题目大意:原题链接 锯木板,锯木板的长度就是花费.比如你要锯成长度为8 5 8的木板,最简单的方式是把21的木板割成13,8,花费21,再把13割成5,8,花费13,共计34,当然也可以先割成16,5 ...
- POJ 3253 Fence Repair(哈夫曼树)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26167 Accepted: 8459 Des ...
- poj 3253 Fence Repair(优先队列+哈夫曼树)
题目地址:POJ 3253 哈夫曼树的结构就是一个二叉树,每个父节点都是两个子节点的和. 这个题就是能够从子节点向根节点推. 每次选择两个最小的进行合并.将合并后的值继续加进优先队列中.直至还剩下一个 ...
- POJ 3253 Fence Repair(优先队列,哈夫曼树,模拟)
题目 //做哈夫曼树时,可以用优先队列(误?) //这道题教我们优先队列的一个用法:取前n个数(最大的或者最小的) //哈夫曼树 //64位 //超时->优先队列,,,, //这道题的优先队列用 ...
- poj3253 Fence Repair【哈夫曼树+优先队列】
Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...
随机推荐
- 引用EChart和Bootstrap
1.怎么引用Echart 下载之后,写一个html,里面这样写 <!DOCTYPE html> <html> <head> <meta charset=&qu ...
- JavaScript中函数和类(以及this的使用<重点>,以及js和jquery讲解,原生js实现jquery)
1.javascript中以函数来表示类: 一般函数是小写开头:function foo() 类开头是大写:function Foo() 实例化类: obj = new Foo() 其他属性就同类是一 ...
- JMS之——ActiveMQ时抛出的错误Could not connect to broker URL-使用线程池解决高并发连接
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/69046395 解决使用activemq时抛出的异常:javax.j ms.JMSE ...
- UVALive - 4636 Cubist Artwork(贪心)
题目链接 题意 给出正视图和侧视图,判断最少用几个立方体 分析 若存在高度相同的立方块,则以数目多的那面为准. #include <iostream> #include <cstdi ...
- FFprobe使用指南
http://blog.csdn.net/stone_wzf/article/details/45378759 http://blog.chinaunix.net/uid-26000296-id-42 ...
- Sublime Text 2 绿色汉化版 x64
前天介绍了<Sublime Text 2 绿化与汉化 [Windows篇]>,应大家要求,我特地做了汉化版分享给大家. 很清新吧,但我没安装多余的插件,只是安装了几个必备的插件,如 输入法 ...
- JavaScript编写风格指南 (三)
七(七):严格模式 // 严格模式应当仅限在函数内部使用,千万不要在全局使用 //不好的写法:全局使用严格模式"user strict"; function doSomething ...
- .Net Core连接RabbitMQ集群
var connectionFactory = new ConnectionFactory() { //HostName = "192.168.205.128", 集群不在此处声明 ...
- win7下iis中配置php.ini文件
将php.ini-development配置文件重命名为php.ini配置文件即可. 接着做如下配置操作: 1.修改php.ini配置文件 打开php.ini配置文件,找到 12 ; On windo ...
- pwd、ln和重定向命令
pwd命令 命令功能: 使用pwd命令可以显示当前的工作目录,该命令很简单,直接输入pwd即可,后面不带参数. pwd命令以绝对路径的方式显示用户当前工作目录.命令将当前目录的全路径名称(从根 ...