2015 多校联赛 ——HDU5350(huffman)
Stilwell is very confused about this function, and he need your help.
First of all, given n positive
integers Ai and Ai≥Ai+1.
Then, generate n positive
integers Bi
Define f(i,j) for i,j∈Z
Find f(n,1).
the number of test cases.
For each test case, the first line contains a positive integer n,
and the next line contains n positive
integers Ai.
T≤100, 1≤n≤105, ∑n≤106, 1≤Ai≤104.
a line.
3
1 1 1
5
28 26 25 24 1
10
996 901 413 331 259 241 226 209 139 49
233
11037
//完全没看出来是个huffman - -!
#include <iostream>
#include <cstdio>
#include<algorithm>
#include<cstring>
#include<functional>
#include<queue>
typedef long long ll;
using namespace std; int main()
{
int T;
int n,a;
priority_queue<ll, vector<ll>, greater<ll> >q;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
while(!q.empty())
{
q.pop();
}
for(int i=1; i<=n; i++)
{
scanf("%d",&a);
q.push(a);
}
ll sum = 0;
while(!q.empty())
{
ll x = q.top();
q.pop();
if(q.empty())
{
continue;
}
ll y = q.top();
q.pop();
ll tmp= x + y;
sum+=tmp;
q.push(tmp);
}
printf("%I64d\n",sum);
}
return 0;
}
2015 多校联赛 ——HDU5350(huffman)的更多相关文章
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2015 多校联赛 ——HDU5319(模拟)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- 2015 多校联赛 ——HDU5301(技巧)
Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...
- 2015 多校联赛 ——HDU5303(贪心)
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
随机推荐
- 2017-2018-1 1623 bug终结者 冲刺006
bug终结者 冲刺006 by 20162328 蔡文琛 今日任务:音频素材添加 又是新的一天,小组项目有了很大的起色,已经可以在手机上试玩了. 添加背景音乐能使我们的游戏锦上添花. 音频资源需求 需 ...
- 冲刺NO.1
Alpha冲刺第一天 站立式会议 项目进展 项目的第一天,主要工作是对项目的开发进行规划,以及将规划的成果转化为燃尽图与博客文章.依据项目需求分析报告与开题报告中已经完成的设计任务和项目规划,我们将系 ...
- python的Flask 介绍
Flask 介绍 知识点 微框架.WSGI.模板引擎概念 使用 Flask 做 web 应用 模板的使用 根据 URL 返回特定网页 实验步骤 1. 什么是 Flask? Flask 是一个 web ...
- continue和break的特殊用法。
break在程序中一般来说的作用就是跳出当前循环,然后再据需执行循环外的语句.continue也是对当前循环来说直接进入到下一次循环.其实我们在程序中有时候循环体嵌套太多,进行到某一步是希望直接bre ...
- 解决java.lang.NoSuchMethodError:org.joda.time.DateTime.withTimeAtStartOfDay() Lorg/joda/time/DateTime
问题:项目放在weblogic运行,报错 java.lang.NoSuchMethodError: org.joda.time.DateTime.withTimeAtStartOfDay()Lorg/ ...
- nyoj 开方数
开方数 时间限制:500 ms | 内存限制:65535 KB 难度:3 描述 现在给你两个数 n 和 p ,让你求出 p 的开 n 次方. 输入 每组数据包含两个数n和p.当n和p都为0 ...
- Spring知识点回顾(08)spring aware
Spring知识点回顾(08)spring aware BeanNameAware 获得容器中的bean名称 BeanFactoryAware 获得当前的bean factory Applicatio ...
- Extensions in UWP Community Toolkit - Mouse Cursor
概述 UWP Community Toolkit Extensions 中有一个为 Mouse 提供的扩展 - Mouse Cursor Extensions,本篇我们结合代码详细讲解 Mouse C ...
- java线程池01-ThreadPoolExecutor构造方法参数的使用规则
为了更好的使用多线程,JDK提供了线程池供开发人员使用,目的在于减少线程的创建和销毁次数,以此达到线程的重复利用. 其中ThreadPoolExecutor是线程池中最核心的一个类,我们先简单看一下这 ...
- Python之内置函数
内置函数 python里的内置函数.截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是python提供给你直接可以拿来使用的所有函数. 分类学习内置函数: 总共 ...