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的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- hdu 2501 Tiling_easy version 递推
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2501 题目分析:已知有2*1,2*2,两种型号的瓷砖,要求铺满2*n的格子有多少种方法.可以考虑最左边 ...
- linux exec函数族
1.简介 在Linux中,并不存在exec()函数,exec指的是一组函数,一共有6个,分别是: #include <unistd.h> extern char **environ; ...
- 支持向量机 support vector machine
SVM(support Vector machine) (1) SVM(Support Vector Machine)是从瓦普尼克(Vapnik)的统计学习理论发展而来的,主要针对小样本数据进行学习. ...
- [Guava源码分析]ImmutableCollection:不可变集合
摘要: 我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3888557.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的 ...
- 防止双击选中html中文字
在开发过程中很常用的会给<span></span>等内联元素增加一个onlick事件,但是经常发生的一件事情就是点击的时候,选中了span中的字体:倒是不影响主逻辑,但是很难受 ...
- Android String format 通过value 下的string.xml 文件
<string name="format_coordinate" formatted="false">%s %d° %d\' %d\" % ...
- NSS_06 extjs弹出窗口上的文本框默认获得焦点
这个问题其实是个窗户纸, 没什么技术含量,但是做的过程中有点曲折, 所以也记录下来吧. Ext.window.Window中有focus(o1, o2)方法, 作用:Try to focus this ...
- 例题6-7 Trees on the level ,Uva122
本题考查点有以下几个: 对数据输入的熟练掌握 二叉树的建立 二叉树的宽度优先遍历 首先,特别提一下第一点,整个题目有相当一部分耗时在了第一个考查点上(虽然有些不必要,因为本应该有更简单的方法).这道题 ...
- nginx服务器配置多域名
nginx服务器支持配置多站点,我们可以通过配置子域名让你的一个域名下放置多个项目. 那么如何实现这个过程呢? 网络上的许多方案,有些写的过于繁杂,有些则是配置有误,或者说,有些配置项是要根据自己的主 ...
- Messages.pas里的消息
一.Windows 消息大全 这张表拷贝自万一兄的帖子:http://www.cnblogs.com/del/archive/2008/02/25/1079970.html 但是我希望自己能把这些消息 ...