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的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- 9款超绚丽的HTML5/CSS3应用和动画特效
1.CSS3飘带状3D菜单 菜单带小图标 这次我们要来分享一款很特别的CSS3菜单,菜单的外观是飘带状的,并且每一个菜单项有一个精美的小图标,鼠标滑过菜单项时,菜单项就会向上凸起,像是飘带飘动一样,形 ...
- 使用Linux系统中的SSH服务
使用Linux系统中的SSH服务 1.SSH服务应用场景 ① 可以实现对文件的上传与下载 ② 实现远程管理Linux 2.安装SSH服务器 服 务:sshd 位 置:光盘2 软 件:openssh-s ...
- ThinkPHP框架概述
框架概述 1.什么是框架 框架,即framework.其实就是某种应用的半成品,就是一组组件,供你选用完成你自己的系统. 2.框架的应用场景 ① 代码重用 ② 合理分工 ③ 解决团队协作开发问题 3. ...
- DataGrid1
2013-09-2512:26:31 1.DataGrid页面 <asp:DataGrid ID="msgInfo1" PageSize="8" Auto ...
- 向CodeBlocks的Project中添加calss文件时,出现No such file or directory错误的解决方案
我们在CodeBlocks中编写程序时,一般要建立工程.现在建立工程first,然后建立类文件Person,并将其添加到first中, int main() { Person p; p.display ...
- 运行maven报错:经过检查是因为maven不兼容jdk1.6,重新安装1.7解决
cmd mvn -v报错: Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apach ...
- Windows下MySQLroot密码破解
Win下MySQL修改root密码的多种方法 ##win2003mysql的密码破解 方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PA ...
- JS重写alert,保证弹窗错误的友好性
// ------------------------------------------------------------- // 重写alert,保证弹窗错误的友好性 var j_oldAler ...
- Android 多国语言
参考android 开发文档, ISO 639-1 ISO 3166-1-alpha-2 关于中国的: 中国其他地区: https://en.wikipedia.org/wiki/ISO_3166 ...
- PHP获取上个月、下个月、本月的日期(strtotime(),date())
今天写程序的时候,突然发现了很早以前写的获取月份天数的函数,经典的switch版,但是获得上月天数的时候,我只是把月份-1了,估计当时太困了吧,再看到有种毛骨悚然的感觉,本来是想再处理一下的,但是一想 ...