题目链接:

https://vjudge.net/problem/POJ-3253

题目大意:

有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度

给定各个要求的小木板的长度,及小木板的个数n,求最小费用

思路:

HUffman算法

优先队列

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
int n;
int main()
{
while(scanf("%d", &n) != EOF)
{
priority_queue<int, vector<int>, greater<int> >q;
int x;
for(int i = ; i < n; i++)
{
scanf("%d", &x);
q.push(x);
}
ll ans = ;
while(q.size() > )
{
int a = q.top();
q.pop();
int b = q.top();
q.pop();
q.push(a + b);
ans += (a + b);
}
cout<<ans<<endl;
}
return ;
}

POJ-3253 Fence Repair---Huffman贪心的更多相关文章

  1. POJ - 3253 Fence Repair 优先队列+贪心

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

  2. poj 3253 Fence Repair (贪心,优先队列)

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

  3. POJ 3253 Fence Repair (贪心)

    题意:将一块木板切成N块,长度分别为:a1,a2,……an,每次切割木板的开销为当前木板的长度.求出按照要求将木板切割完毕后的最小开销. 思路:比较奇特的贪心 每次切割都会将当前木板一分为二,可以按切 ...

  4. POJ 3253 Fence Repair(修篱笆)

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

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

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

  6. poj 3253 Fence Repair 优先队列

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

  7. POJ 3253 Fence Repair (贪心)

    Fence Repair Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  8. POJ 3253 Fence Repair 贪心 优先级队列

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 77001   Accepted: 25185 De ...

  9. [ACM] POJ 3253 Fence Repair (Huffman树思想,优先队列)

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25274   Accepted: 8131 Des ...

  10. poj 3253 Fence Repair 贪心 最小堆 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=3253 题解 本题是<挑战程序设计>一书的例题 根据树中描述 所有切割的代价 可以形成一颗二叉树 而最后的代价总和是与子节点和深 ...

随机推荐

  1. 关于标准ui设计图转换为H5页面的终端适配

    一些基本概念 在进行具体实战之前,首先得了解下面这些基本概念(术语): 视窗 viewport 简单的理解,viewport是严格等于浏览器的窗口.在桌面浏览器中,viewport就是浏览器窗口的宽度 ...

  2. TypeScript入门(三)面向对象特性

    一.类(Class) 类是ts的核心,使用ts开发时,大部分代码都是写在类里面. 1.类的声明 多个对象有相同的属性和方法,但是状态不同. 声明类的属性和方法时可以加 访问控制符,作用是:类的属性和方 ...

  3. CSS(CSS3)选择器(2)

    该部分主要为CSS3新增的选择器 接上一篇 CSS(CSS3)选择器(1) 一.通用兄弟选择器: 24:E ~ F,匹配任何E元素之后的同级F元素. div ~ p{ background-color ...

  4. laravel 原生 sql

    1.插入数据 DB::insert('insert into users (id, name, email, password) values (?, ?, ? , ? )',[1, 'Laravel ...

  5. http,socks4,socks5代理的区别

    HTTP代理 能够代理客户机的HTTP访问,主要是代理浏览器访问网页,它的端口一般为80.8080.3128等: SOCKS代理 SOCKS代理与其他类型的代理不同,它只是简单地传递数据包,而并不关心 ...

  6. bug单的生命周期

    测试工程师发现了软件的缺陷(bug),那修复bug的整个流程是怎么样的呢? 1.发现bug 2.和开发确认是否是bug 3.如果是bug则提bug单到测试经理,如果不是则放过 4.测试经理把bug单走 ...

  7. 云计算--网络原理与应用--20171123--网络地址转换NAT

    NAT的概述 NAT的配置 实验 一. NAT的概述 NAT(Network address translation,网络地址转换)通过将内部网络的的私有地址翻译成全球唯一的共有网络IP地址,是内部网 ...

  8. uboot中的命令体系

    一.uboot的命令体系介绍以及实例分析: U-Boot 的命令实现大多在 common 目录下.在该目录下命令的代码文件都是以“ cmd_”开头的,如下图所示: 其中每一个文件都是一个命令实现的代码 ...

  9. C语言第二次博客作业——分支结构

    一.PTA实验作业 题目1:计算分段函数 1.实验代码 #include<stdio.h> #include<math.h> int main(void) { double x ...

  10. 团队作业5-测试与发布(AIpha版本)

    对于已完成的项目我们进行了诸多测试,找到了少许bug,对着这些bug我们在改进的基础上提出了新的目标. 1,测试环境:个人笔记本.个人台式机.环境windows7.网络校园网加移动vpn,浏览器360 ...