UVALive 6533
哈夫曼树 倒过来思考 ~
最深的叶子 值为1 所以最深的先出队列
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue> using namespace std; struct node
{
long long d, v;
node(int i, int j)
{
d = i, v = j;
}
node() {}
bool operator < (node a) const
{
return d < a.d || (d == a.d && v > a.v);
}
}; priority_queue <node> q; int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
q.push(node(x, 0));
}
long long a, b, ans = 0, val = 1;
while((int)q.size() >= 2)
{
int cur = q.top().d;
a = q.top().v, q.pop();
b = q.top().v, q.pop();
if (!a)
a = val;
if (!b)
b = val;
val = max(val, max(a, b));
node t;
t.d = cur - 1, t.v = a + b;
q.push(t);
}
ans = q.top().v, q.pop();
printf("%lld\n", ans);
}
return 0;
}
UVALive 6533的更多相关文章
- The 2013 South America/Brazil Regional Contest 题解
A: UVALive 6525 cid=61196#problem/A" style="color:blue; text-decoration:none">Atta ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- UVALive 6948 Jokewithpermutation dfs
题目链接:UVALive 6948 Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- JS字符串截取
substr 方法返回一个从指定位置开始的指定长度的子字符串. stringvar.substr(start [, length ]) 参数stringvar 必选项.要提取子字符串的字符串文字或 S ...
- BeanDefinition的Resource定位——2
1.FileSystemXmlApplicationContext的实现 public class FileSystemXmlApplicationContext extends AbstractXm ...
- JS学习笔记 -- 定时器,提示框的应用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JSP_EL使用
JSP中EL表达式的简单介绍和使用 参考资料: http://www.java3z.com/cwbwebhome/article/article8/8124.html?id=2453 http ...
- Template_17_metaprogram
1,模板实例化机制是一种基本的递归语言机制,可以用于在编译期执行复杂计算.2,枚举值和静态常量在原来的C++编译器中,在类声明的内部,枚举值是声明"真常值"(常量表达式)的唯一方法 ...
- linux kernel with param
Linux kernel support pass param to kernel, this params can be assigned at load time by insmod or mod ...
- JDK 与 JRE (转)
很多程序员已经干了一段时间java了依然不明白jdk与jre的区别.JDK就是Java Development Kit.简单的说JDK是面向开发人员使用的SDK,它提供了Java的开发环境和运行环境. ...
- apache ab的安装步骤
1:到apache官方网站http://httpd.apache.org/download.cgi#apache24下载最新版本的apache,然后解压,执行如下命令: ./configure –pr ...
- 无法解决 equal to 运算中 "Chinese_PRC_BIN" 和 "Chinese_PRC_CI_AS" 之间的排序规则冲突
无法解决 equal to 运算中 "Chinese_PRC_BIN" 和 "Chinese_PRC_CI_AS" 之间的排序规则冲突.问题如下图: 执行一下语 ...
- SQL统计——按照各种维度
在SQLserver中可以按照各种维度进行统计,实现与EXCLE一样强大的功能. --========================== --Blog:<奔跑的金鱼> --Desc:&l ...