POJ 3253 Fence Repair(贪心)

POJ3253-POJ3253-Fence Repair【STL优先队列】 北大POJ3253-POJ3253-Fence Repair【STL优先队列】 解题报告+AC代码 立即下载

Fence Repair
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 29580 Accepted: 9621

Description

Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He then purchases a single long board just long enough to saw into the N planks (i.e., whose length is the sum of the lengths Li). FJ is ignoring the "kerf", the extra length lost to sawdust when a sawcut is made; you should ignore it, too.

FJ sadly realizes that he doesn't own a saw with which to cut the wood, so he mosies over to Farmer Don's Farm with this long board and politely asks if he may borrow a saw.

Farmer Don, a closet capitalist, doesn't lend FJ a saw but instead offers to charge Farmer John for each of the N-1 cuts in the plank. The charge to cut a piece of wood is exactly equal to its length. Cutting a plank of length 21 costs 21 cents.

Farmer Don then lets Farmer John decide the order and locations to cut the plank. Help Farmer John determine the minimum amount of money he can spend to create the N planks. FJ knows that he can cut the board in various different orders which will result in different charges since the resulting intermediate planks are of different lengths.

Input

Line 1: One integer  N, the number of planks 
Lines 2.. N+1: Each line contains a single integer describing the length of a needed plank

Output

Line 1: One integer: the minimum amount of money he must spend to make  N-1 cuts

Sample Input

3
8
5
8

Sample Output

34

Hint

He wants to cut a board of length 21 into pieces of lengths 8, 5, and 8. 
The original board measures 8+5+8=21. The first cut will cost 21, and should be used to cut the board into pieces measuring 13 and 8. The second cut will cost 13, and should be used to cut the 13 into 8 and 5. This would cost 21+13=34. If the 21 was cut into 16 and 5 instead, the second cut would cost 16 for a total of 37 (which is more than 34).

Source



思路:构造哈夫曼树






Hi3516CV610开发板实战:从零搭建智能视觉监控系统 本文详细介绍了从零开始基于Hi3516CV610开发板搭建智能视觉监控系统的完整实战流程。涵盖硬件连接、系统配置、摄像头集成、网络设置、固件烧录到视频处理与智能分析功能开发,提供了丰富的实践经验和调试技巧,帮助开发者快速掌握嵌入式视觉系统开发。 阅读详情

相关推荐

QMT量化交易桥接方案深度对比:从MiniQMT淘汰说起

量化交易系统中的API桥接,本质是解决本地终端与底层交易引擎之间的通信瓶颈。其核心原理在于绕过GUI封装、直连确定性执行层,从而获得低延迟、高可靠、可监控的指令通路。技术价值体现在策略实盘一致性提升、毫秒级响应保障及运维可控性增强。典型应用场景包括打板策略、T+0套利、高频网格等对时效与稳定性双敏感的自动化交易。本文聚焦国金证券QMT专业版生态,系统剖析DLL注入、HTTP反向代理、IPC共享内存与官方HTTP API四大桥接路径的性能边界、合规风险与工程落地成本,尤其深入解析qmt终端 client is

weixin_33892359的博客 457

Fence Repair(优先队列)

A - Fence Repair Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He then purchases a si

weixin_46029049的博客 480

CANdelaStudio实战:如何用19服务快速编辑DTC快照数据(附Excel模板)

本文详细介绍了在CANdelaStudio中利用19服务高效编辑DTC快照数据的进阶技巧。通过导出DTC池至Excel进行批量编辑,结合‘Copy from DTC Pool’功能实现配置复用,并分享了构建自定义Excel模板与字段映射的实用方法,帮助工程师将繁琐的手动配置转化为工程化的批量处理,大幅提升诊断数据库开发效率。

weixin_29230773的博客 190

借锯子的农民

#原题: Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ...

wddmc的博客 370

三相Vienna整流器过零点电流畸变?试试这个SVPWM调制波补偿技巧

本文针对三相Vienna整流器在电流过零点附近出现的电流畸变问题,提出了一种基于SVPWM调制波补偿的有效解决方案。该方法通过注入零序分量重构占空比,巧妙解决因拓扑约束导致的调制矛盾,在基本不增加计算复杂度的前提下,显著平滑电流波形,降低THD。

weixin_29212867的博客 114

DFT知识点扫盲——DFT scan chain

实际在项目中synccell一般直接上ULVT,既然是SDF,就是带Scan接口的DFF,SN (set negtive)是低置位,RP(reset positive)是高复位,既没有SN也没有RP的就是无复位寄存器。1:定义:满足可测试性设计(DFT),将设计中所有的触发器连接到一条或者若干条链上,称为scan chain,将一个复杂的时序电路转换为简单的组合电路进行测试,这一步是在逻辑综合(DC)中实现。当SE=1当SI=1时,电路进入scan状态,当SI=0时,电路工作在normal状态。

笨蛋大乌龟的博客 4933

哈夫曼树-Fence Repair

Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32424 Accepted: 10417DescriptionFarmer John wants to repair a small length of the fence around the pasture. He meas

绝尘 835

基于步科(Kinco HMI 2.5)的组态软件使用

本篇介绍Kinco HMI 2.5的组态软件使用,图标如下 目录   一、新建工程并配置连接 1.1 根据工程选择PLC与HMI型号 1.2 配置PLC连接与选项 二、组态画面编辑 2.1 打开画面窗口 2.2 编辑画面 2.3 组态变量与PLC程序变量连接 三、组态程序下载到HMI 3.1 连接 3.2 编译 3.3 下载 一、新建工程并配置连接 1.1 根据工...

ACanswer的专栏 1万+

Fence Repair(P3253)

要用long long 不然就是一直在WA,,发现数组不够大的时候,有时会显示WA,有时会显示Rumtime Error #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int m

jiangjiashi的博客 671

NVIDIA Isaac Sim 入门教程 - 运动生成控制器(Motion Generators)

机器人任务通常在任务空间中根据所需的末端执行器轨迹进行定义,而控制动作则在关节空间中执行。这自然会产生关节空间和任务空间(操作空间)控制方法。然而,要利用运动控制成功执行交互任务,往往需要对机械臂及其环境都建立精确的模型。虽然可以知道足够精确的机械臂模型,但很难获得详细的环境描述 [SSVO09]。可以通过在交互过程中引入顺应行为来克服这种不匹配造成的规划错误。虽然顺应性可以通过机器人的结构(如弹性致动器、软机械臂)被动实现,但我们对侧重于主动交互控制的控制器设计更感兴趣。这些设计大致分为注释。

2506_90492529的博客 1577

2024年11月架构设计师案例分析真题回顾,附参考答案、解析及所涉知识点(一)

软考高级系统架构设计师考试包含三个科目:信息系统综合知识、案例分析和系统架构设计论文。考试形式为机考。本文主要回顾2024年下半年(2024-11-10)系统架构设计师考试上午第二科案例分析的题目,同时附带参考解答、解析和所涉知识点。

一几文的编程学习笔记。 2418

poj 3253 Fence Repair 贪心

poj 3253 Fence Repair 题目链接: http://poj.org/problem?id=3253 思路: 哈夫曼树型贪心 自底向上每次挑选两个最小的数值相加,相加的值从新合并到数组中,继续挑选相加 如果每次都要排序的话会超时.... 代码: #include <iostream> #include <algorithm> #include ...

ddqb3235的博客 236

使用MATLAB结合EasySpin进行ESR模拟的详细步骤及示例代码

安装EasySpin:确保你已经安装了EasySpin工具箱,它可以帮助你进行ESR模拟。你可以从EasySpin的官方网站(https://easyspin.org/)下载并安装。准备实验数据:将实验得到的EPR数据整理成合适的格式,一般包含磁场(Magnetic Field)和信号强度(Intensity)两列。进行模拟:使用EasySpin的函数对单线态氧自由基和超氧自由基进行模拟。调整参数:通过调整模拟参数,使模拟得到的峰型和峰位置与实验数据尽可能匹配。导出数据。

AI的内部世界的博客 2004

【题解】POJ 3253 Fence Repair(贪心)

POJ 3253 Fence Repair https://vjudge.net/problem/POJ-3253 原题 农场主约翰想修理牧场周围一小段篱笆。他测量了栅栏,发现他需要N(1≤N≤20,000)块木板,每块都有整数Li(1≤Li≤50,000)个单位。然后他买了一块长木板,刚好能锯进N块厚木板(也就是木板,其长度为长度Li的和)。FJ忽略了“切缝”,即锯切时锯屑失去的额外长度;你也应该忽略它。 FJ悲伤地意识到他没有锯子来锯木头,所以他就用这块长木板来到农民Don的农场,礼貌地问他是否可

bu_shushu的博客 1516

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

【贪心】POJ 3253:Fence Repair

一、题目内容 POJ 3253 原题地址 二、题意解释 有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度,给定各个要求的小木板的长度,及小木板的个数n,求最小费用 如 3 8 8 5: 先从无限长的木板上锯下长度为 21 的木板,花费 21 再从长度为21的木板上锯下长度为5的木板,花费5 再从长度为16的木板上锯下长度为8的木板,花费8 总花费 = 21+5+8 =34 三、代码及注释 #include<stdio.h> #inclu

szy_fasheng的博客 407

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

poj3253 Fence Repair 贪心

Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 41985   Accepted: 13664 Description Farmer John wants to repair a small length of the fence arou

kyoma的博客 461

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

POJ 3253 Fence Repair【贪心】

传送门:POJ 3253 Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 70430 Accepted: 23193 Description Farmer John wants to repair a small length of the fence around the pasture. ...

Waiting For You 242

贪心算法——Fence Repair(POJ 3253)

题目连接 http://poj.org/problem?id=3253 Fence Repair(POJ 3253) 题目描述 Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤...

Uitachi1的博客 480

POJ 3253 fence Repair 一个很有趣的贪心解法

Fence Repair 农夫约翰为了修理栅栏,要将

童凌的技术博客 1346

【OJ】贪心法 Fence Repair POJ 3253 霍夫曼(Huffman)编码原理 acmclub 12326

题目链接: /* 贪心法 Fence Repair POJ 3253 霍夫曼(Huffman)编码原理 */ #include #include typedef long long LL; using namespace std; int l[50010]; int main(){ int j,m=0,n;cin>>n; LL s=0,ans=0; for(int i=0;i>l

Wu_Being 的优快云 博客 1058

poj 3253 Fence Repair 贪心

Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 34406   Accepted: 11071 Description Farmer John wants to repair a small length of the fence arou

smilesundream的博客 310

ACM-贪心入门:POJ3253 Fence Repair

ACM-贪心入门:POJ3253 Fence Repair中文题意输入输出示例输入示例输出解决思路AC代码 为简化文章,原题请直接看原题链接 中文题意 给你一块长木板,其长度为L,要求将其切割成若干块指定大小的木板,大小分别为a,b,c,d… 其中L恰好等于a+b+c+d+…,每切割一次,所需的花费为当前执行切割操作的木板的的长度。比如将长度为P的木板切割为K和H,则花费为P。求最小的花费的切割方...

LiJgQg的博客 401

POJ 3253 Fence Repair (贪心)

题目链接:点击打开链接 O(N^2)的贪心算法 题目类似于赫夫曼树,每次选取最小的两个进行组合即可得到代价最小的组合 尴尬地水过= = AC代码如下: #include #include #include using namespace std; int main() { int N; int num[20005]; while(cin>>N)

LFhase‘s Blog 433

POJ(3253)FenceRepair

POJ(3253) Fence Repair Descriptions: Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each ...

LordTech的博客 268

POJ 3253——Fence Repair(贪心)

链接:http://poj.org/problem?id=3253 题解 #include<iostream> #include<queue> #include<vector> using namespace std; typedef long long ll; const int MAX_L=5e4+50; int N; // N是木板切割块数...

享受孤独 277

poj3253 Fence Repair( 贪心 )

题意 : 将一个木板锯成N块(即锯N-1次)。规则是每次将一个长度为L的木板锯成2块(不一定相等), 代价是L元。求N-1次代价的最小值。 开始以为是动态规划了,这题确实可以很容易找到子问题,而且子问题间会出现不少重叠,锯一个木板的代价 = Min{ 锯它的两个子木板的代价之和 } + 所锯木板长度,  但在哪里锯这个木板就很难决定了,子问题数量太多,叉掉。也想过贪心,但没想到是哈弗曼

nvfumayx的专栏 630
上一篇: POJ 1700 Crossing River(贪心)
下一篇: POJ 3190 Stall Reservations(贪心)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值