sdutacm-Fence Repair

FenceRepair

TimeLimit: 2000MS Memory Limit: 65536KB

SubmitStatistic

Problem Description

Farmer John wants to repair a small length of the fencearound the pasture. He measures the fence and finds that he needs N (1≤ N ≤ 20,000) planks of wood, each having some integerlength Li (1 ≤ Li ≤ 50,000)units. He then purchases a single long board just long enough to saw intothe N planks (i.e., whose length is the sum of thelengths Li). FJ is ignoring the "kerf", theextra 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 whichto cut the wood, so he mosies over to Farmer Don\'s Farm with this long boardand politely asks if he may borrow a saw.

Farmer Don, a closet capitalist, doesn\'t lend FJ a sawbut instead offers to charge Farmer John for each of the N-1 cutsin 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 andlocations to cut the plank. Help Farmer John determine the minimum amount ofmoney he can spend to create the N planks. FJ knows that hecan cut the board in various different orders which will result in differentcharges 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-1cuts



Example Input

3

8

5

8

Example Output

34

Hint

 

Author

#include <iostream>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<stdlib.h>
#include<algorithm>

using namespace std;
long long sum;
int h[10002];

int main()
{
    priority_queue<int,vector<int>,greater<int> >q;
    int n,i,a,b,c;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&h[i]);
        q.push(h[i]);
    }
    sum = 0;
    while(!q.empty())
    {
        a = q.top();
        q.pop();
        if(!q.empty())
        {
           b = q.top();
           q.pop();
           c = a+b;
           q.push(c);
           sum += c;
        }
    }
    printf("%lld\n",sum);
    return 0;
}
/*题目大意:FJ需要修补牧场的围栏,他需要 N 块长度为 Li 的木头(N planks of woods)。开始时,FJ只有一块无限长的木板,因此他需要把无限长的木板锯成 N 块长度

为 Li 的木板,Farmer Don提供FJ锯子,但必须要收费的,收费的标准是对应每次据出木块的长度,比如说测试数据中 5 8 8,一开始,FJ需要在无限长的木板上锯下长度 21 的木板(5+8+8=21),第二次锯下长度为 5 的木板,第三次锯下长度为 8 的木板,至此就可以将长度分别为 5 8 8 的木板找出


题目可以转化为Huffman树构造问题 :

给定 N planks of woods,

1.   在 N planks 中每次找出两块长度最短的木板,然后把它们合并,加入到集合A中,

2.  在集合中找出两块长度最短的木板,合并加入到集合A中,重复过程,直到集合A中只剩下一个元素

显然,通过每次选取两块长度最短的木板,合并,最终必定可以合并出长度为 Sum(Li)的木板,并且可以保证总的耗费最少
*/

/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 12ms
Take Memory: 428KB
Submit time: 2017-02-09 09:41:23
****************************************************/


 

Tweaking.com - Windows Repair 1.9.18老朽痴拙汉化便携版(系统修复)是一个免费的绿色软件,解压后就可以开始使用。windows是一个脆弱的操作系统,安装软件,过度优化等操作都会让其运行不稳定,或者崩溃。所以当你发现系统有小问题的时候,你就应该想办法修复它,从而避免错误的扩散。这次介绍的Windows Repair就是一个有针对性的修复软件,如果你束手无策,那么使用它可能会有意想不到的效果。这个软件支持的系统也是非常广泛。windows xp,2003,vista、2008、windows 7、windows 8 都可以使用它。   打开这个软件后,是一个向导式的界面,上面有步骤。其实我们只需要选中其中的“开始修复”界面,然后使用“自定义模式”这个自定义修复模式。   点击 开始 后就会看到自己选择需要修复的项目。 Windows Repair所有能够修复的windows问题:   1、重置注册表权限。   2、重置文件权限。   3、注册系统文件。   4、修复wmi.(一项核心的windows管理技术),可能也就是windows自带的“管理”功能。   5、修复windows防火墙。   6、修复ie浏览器。   7、修复MDAC和MS jet。(微软数据库访问组件和资料引擎)   8、还原host文件。   9、修复图标。 10、修复winsock和刷新DNS缓存。   11、删除临时文件。   12、修复代理设置。   13、不隐藏非系统文件。   14、修复windows更新功能。 ...... Tweaking.com - Windows Repair Change Log. v1.9.18 Bug fix: The program would get stuck in a opening and closing loop when you had it set to auto restart after repairs. This was because of a timer not turning off and wanting to update the window while it was closing down, thus the loop. This has now been fixed and the program closes like it should. New feature: Since I had to get this bug fixed quickly I decided to take the time to add a new feature I came up with. In the steps before the repairs, Step 2 asks the user to do a check disk (chkdsk) on the system to make sure there is no file system errors before doing any repairs. I hated the fact that I forced the user to reboot to scan it when there may not be any errors on the file system. So I have added a new option to this step where the program will check the drive for errors and let you know if any are found. It is done by making a pipe to a cmd.exe window and running chkdsk in read only mode. Once chkdsk is done it looks for the key words "Windows found problems" and can let the user know if running chkdsk is even needed. Thus saving the user a reboot if there are no errors. I also have it log the chkdsk results to a chkdsk.log file in the logs folder in case a user wants to see the results of the chkdsk. :-)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值