题目: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. 在Linux环境下给php添加mbstring扩展

    1,今天在开发项目的时候使用了一个php函数(mb_strcut),运行代码时候提示报错"call to undefind function mb_strcut",首先检查下函数名 ...

  2. 通过 SuperObject 生成 json string

    (* { "name": "Henri Gourvest", /* this is a comment */ "vip": true, &q ...

  3. 转 IHttpModule不起作用

    在 Visual Studio 中,测试 IHttpModule(httpModules) 正常,但是放到服务器上去就不起作用了,这多半得多服务器 IIS 配置入手. 一.看“应用程序池”的“托管管道 ...

  4. ubuntu下Django的下载与安装(三种方法)

    方法一: 1下载: 1 安装python,Linux系统下,一般是安装好的,可以输入如下命令查看 python -V 如果没有安装,则需要安装,安装方法如下,首先从官网下载源码,然后: (1) $ t ...

  5. 1021.Deepest Root (并查集+DFS树的深度)

    A graph which is connected and acyclic can be considered a tree. The height of the tree depends on t ...

  6. VS2010中无法嵌入互操作类型“......”,请改用适用的接口的解决方法

  7. 解决ora-01652无法通过128(在表空间temp中)扩展temp段

    问题描述: 今天建索引的时候报:ora-01652无法通过128(在表空间temp中)扩展temp段 1.查看表空间是自动增长,且建表空间时是没有设表空间最大值的. 2.查看了一下表空间剩余多少竟然只 ...

  8. .net google calendar

    https://developers.google.com/gdata/client-cs http://www.codeproject.com/Articles/64474/How-to-Read- ...

  9. window live writer的曲折安装过程

           之前一直使用windows live writer2012写日志,由于之前重装了系统,所以需要重新安装writer,本以为是一个很简单的过程,你就是安装个软件吗.... 然而事实是... ...

  10. 一个简单的aJax——后台用servlet技术

    示例:webDemo 一.客户端 <%-- Created by IntelliJ IDEA. User: Administrator Date: 15-12-2 Time: 上午5:41 To ...