POJ-3253 Fence Repair
来源:互联网 发布:mac网络共享无法连接 编辑:程序博客网 时间:2024/06/06 14:37
/************************************************* Author :somniloquy* Created Time :2015/10/18 10:08:15 ************************************************/#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>#include <queue>using namespace std;const int n_max = 2e4 + 5;int len[n_max], n;long long ans;priority_queue <int, vector<int>, greater<int> > fence;int main(void){ while(~scanf("%d", & n)) { for(int i = 0; i < n; i ++) { scanf("%d", & len[i]); fence.push(len[i]); } ans = 0; while(!fence.empty()) { int len_1 = fence.top(); fence.pop(); if(fence.empty()) break; int len_2 = fence.top(); fence.pop(); int len_3 = len_1 + len_2; ans += len_3; fence.push(len_3); } printf("%I64d\n", ans); } return 0;}
题目:
(摘自 小優YoU)
有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度
给定各个要求的小木板的长度,及小木板的个数n,求最小费用
以3 5 8 5为例:
先从无限长的木板上锯下长度为 21 的木板,花费 21
再从长度为21的木板上锯下长度为5的木板,花费5
再从长度为16的木板上锯下长度为8的木板,花费8
总花费 = 21+5+8 =34
题解:
优先队列,每次取出队列中的2个最小值,合并后再放入队列,直到队列元素只有一个。注意ans的范围 longlong。
0 0
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253Fence Repair
- POJ--3253 -- Fence Repair
- poj-3253-Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- poj 3253 Fence Repair
- POJ - 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- poj 3253---Fence Repair
- Android高效加载大图片,防止OOM
- 在Eclipse中应该怎样去修改Android应用程序的包名(注意按步骤修改)
- MySQL用户远程访问权限开通
- js语法 关键字 变量
- iOS所有常用证书,appID,Provisioning Profiles配置说明及制作图文教程
- POJ-3253 Fence Repair
- 【codevs】2292图灵机游戏
- 详解如何使用DockerHub官方的mysql镜像生成容器
- 日经春秋 20151018
- MATLAB GUI设计手写输入板
- C语言获取文件大小相关操作
- LeetCode解题报告--Remove Element
- Android 开发者的 RxJava 详解
- 完全卸载Oracle11g数据库