题目: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 (哈夫曼树 优先队列)的更多相关文章

  1. Poj 3253 Fence Repair(哈夫曼树)

    Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...

  2. BZOJ 3253 Fence Repair 哈夫曼树 水题

    http://poj.org/problem?id=3253 这道题约等于合并果子,但是通过这道题能够看出来哈夫曼树是什么了. #include<cstdio> #include<c ...

  3. POJ 3253 Fence Repair(哈夫曼编码)

    题目链接:http://poj.org/problem?id=3253 题目大意: 有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度 给定各个 ...

  4. POJ 3253 Fence Repair【哈弗曼树/贪心/优先队列】

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 53645   Accepted: 17670 De ...

  5. POJ 3253 Fence Repair(简单哈弗曼树_水过)

    题目大意:原题链接 锯木板,锯木板的长度就是花费.比如你要锯成长度为8 5 8的木板,最简单的方式是把21的木板割成13,8,花费21,再把13割成5,8,花费13,共计34,当然也可以先割成16,5 ...

  6. poj3253 Fence Repair【哈夫曼树+优先队列】

    Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...

  7. POJ 3253 Fence Repair(修篱笆)

    POJ 3253 Fence Repair(修篱笆) Time Limit: 2000MS   Memory Limit: 65536K [Description] [题目描述] Farmer Joh ...

  8. poj 3253 Fence Repair 优先队列

    poj 3253 Fence Repair 优先队列 Description Farmer John wants to repair a small length of the fence aroun ...

  9. POJ 3253 Fence Repair (优先队列)

    POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the past ...

随机推荐

  1. php 操作数组 (合并,拆分,追加,查找,删除等)

    1. 合并数组 array_merge()函数将数组合并到一起,返回一个联合的数组.所得到的数组以第一个输入数组参数开始,按后面数组参数出现的顺序依次迫加.其形式为: array array_merg ...

  2. 2015年1月最新中国行政区划县及以上代码mysql数据库

    中华人民共和国国家统计局>> 行政区划代码>>mysql数据格式 截图如下 行政区划mysql数据库文件下载:nation.zip 转载:http://www.sdhack.c ...

  3. phpcms v9修改栏目描述的多行文本为编辑器方法

    phpcms v9在添加栏目的时候,栏目描述为多行文本,无法满足有图片,以及格式的修改调整,那么仿站网今天告诉大家如何将他改为编辑器,方法如下 找到phpcms/moudles/admin/templ ...

  4. Inside Microsoft SQL Server 2008: T-SQL Querying 读书笔记1

    (5)SELECT   (5-2) DISTINCT    (5-3)TOP(<top_specifications>)   (5-1)<select_list> (1)FRO ...

  5. max_size, capacity and size 的区别

    The max_size() function returns the maximum number of elements that the container can hold. The max_ ...

  6. 一些shell脚本实例

    在群里也混了不少时间了.总结一些实例 #统计QQ消息里面某个用户改名字的记录# awk -f# 聊改名字记录#特殊例子 例如#2013-11-28 9:23:56 北京-AA-Vip<12345 ...

  7. Xubuntu 安装mentohust

    对于路由器上网到用户来说,自动分配IP上网。 对于校园网用户,首先下载mentohust_0.3.4-1_i386.deb,双击安装程序 然后在命令窗口中输入sudo -s 密码:user来获得roo ...

  8. ASP.NET MVC的约定

    ASP.NET MVC 应用程序遵循以下3条约定: 所有的控制器的名称都以Controller结尾,如HomeController, AccountController 这些类默认在Controlle ...

  9. 【学习总结】IOS程序运行过程 、UIWindow 、controller 、 UIView 创建过程的总结

    程序启动开始到view显示: 程序启动首先会执行main函数 - > UIApplicationMain函数: 程序启动 (加载框架,info文件,资源等) 执行Main函数 初始化UIAppl ...

  10. Ext.Ajax.request()方法和FormPanel.getForm().submit()方法,都返回success()方法的差异

    我还是不发表到博客园首页吧,要不然还是要被取消,>_< 还是言归正传吧,关于Ext.Ajax.request()方法和FormPanel.getForm().submit()方法返回suc ...