poj 3253 Fence Repair (哈夫曼树 优先队列)
题目:http://poj.org/problem?id=3253
没用long long wrong 了一次
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std; int main()
{
long long n,i,j,a,sum,cnt;//或者 __int64 n,i,j,a,sum,cnt;
priority_queue<int,vector<int>,greater<int> >pq;
cin>>n;
for(i=; i<n; i++)
{
cin>>a;
pq.push(a);
}
sum=;
while(!pq.empty())
{
cnt=pq.top();
pq.pop();
if(pq.empty())
break;
cnt+=pq.top();
sum+=cnt;
pq.pop();
pq.push(cnt);
}
cout<<sum<<endl;
return ;
}
poj 3253 Fence Repair (哈夫曼树 优先队列)的更多相关文章
- Poj 3253 Fence Repair(哈夫曼树)
Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...
- BZOJ 3253 Fence Repair 哈夫曼树 水题
http://poj.org/problem?id=3253 这道题约等于合并果子,但是通过这道题能够看出来哈夫曼树是什么了. #include<cstdio> #include<c ...
- POJ 3253 Fence Repair(哈夫曼编码)
题目链接:http://poj.org/problem?id=3253 题目大意: 有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度 给定各个 ...
- POJ 3253 Fence Repair【哈弗曼树/贪心/优先队列】
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 53645 Accepted: 17670 De ...
- POJ 3253 Fence Repair(简单哈弗曼树_水过)
题目大意:原题链接 锯木板,锯木板的长度就是花费.比如你要锯成长度为8 5 8的木板,最简单的方式是把21的木板割成13,8,花费21,再把13割成5,8,花费13,共计34,当然也可以先割成16,5 ...
- poj3253 Fence Repair【哈夫曼树+优先队列】
Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...
- POJ 3253 Fence Repair(修篱笆)
POJ 3253 Fence Repair(修篱笆) Time Limit: 2000MS Memory Limit: 65536K [Description] [题目描述] Farmer Joh ...
- poj 3253 Fence Repair 优先队列
poj 3253 Fence Repair 优先队列 Description Farmer John wants to repair a small length of the fence aroun ...
- POJ 3253 Fence Repair (优先队列)
POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the past ...
随机推荐
- jquery横向滚动条
此代码献给wendy 由于工作太忙,下次再整理成插件调用,先记录下来,欢迎同学们提意见. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...
- 各种语言简单的输出Hello World
PHP echo 'Hello World'; Java System.out.println("Hello World"); Shell_(BashShell) echo Hel ...
- 2W/月和1W/月的工作,你会怎么选?
只看标题的话,肯定有不少人会选择月薪 2W 的工作,很明显,钱多嘛!但实际上,这里是有前提的,完整的问题如下: 一份月薪 2W,但加班无底线,基本没有自由时间的工作,和一份月薪 1W,但正常工作时长, ...
- foxtable使用笔记
1.设置关联表窗口的列的顺序:Tables("award.people").SetColVisibleWidth("name|100|sex|100|job|100|ag ...
- Spark Streaming揭秘 Day16 数据清理机制
Spark Streaming揭秘 Day16 数据清理机制 今天主要来讲下Spark的数据清理机制,我们都知道,Spark是运行在jvm上的,虽然jvm本身就有对象的自动回收工作,但是,如果自己不进 ...
- SQL学习中(序)
从校园中走出来已经两年多了,从最初的企业建站到现在的BPM流程开发,深深的感觉到自己底子很差,因此在园子里记录一下学过的知识,以此自勉. 废话到此结束,今天就先来看一下CREATE CHEMA 语句. ...
- 请求管道与IHttpModule接口
IHttpModule向实现类提供模块初始化和处置事件. IHttpModule包含兩個方法: public void Init(HttpApplication context);public vo ...
- bnuoj 1057 函数(模拟)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=1057 [题意]:给定x的值,带入f(x)求函数值 [题解]:注意第一个数的符号可能是'+',这里把我 ...
- 1190: [HNOI2007]梦幻岛宝珠 - BZOJ
Description 给你N颗宝石,每颗宝石都有重量和价值.要你从这些宝石中选取一些宝石,保证总重量不超过W,且总价值最大为,并输出最大的总价值. 数据范围:N<=100;W<=2^30 ...
- Extjs4.2布局——layout: accordion(Ext.layout.container.Accordion)
API这样介绍这种布局: 示例:(来自API)注:打开默认展开第一个面板. Ext.create('Ext.panel.Panel', { title: 'Accordion Layout', wid ...