poj 3253 fence repair
来源:互联网 发布:php里面怎么写html 编辑:程序博客网 时间:2024/05/16 02:01
FJ需要修补牧场的围栏,他需要 N 块长度为 Li 的木头(N planks of woods)。开始时,FJ只有一块无限长的木板,因此他需要把无限长的木板锯成 N 块长度为 Li 的木板,<span style="margin:0px; padding:0px; widows:2; orphans:2">Farmer Don提供FJ锯子,但必须要收费的,收费的标准是对应每次据出木块的长度,比如说测试数据中 5 8 8,一开始,FJ需要在无限长的木板上锯下长度 21 的木板(5+8+8=21),第二次锯下长度为 5 的木板,第三次锯下长度为 8 的木板,至此就可以将长度分别为 5 8 8 的木板找出。求锯完木板的最小花费。
>#include<iostream>#include<vector>#include<queue>using namespace std;struct cmp{bool operator()(const long long a,const long long b)const//后面的const必须加{return a>b;}};int main(void){int n;while(cin>>n){priority_queue<long long,vector<long long>,cmp>Queue;for(int i=1;i<=n;i++){long long temp;scanf("%I64d",&temp);Queue.push(temp);}long long mincost=0;while(Queue.size()>1){long long a=Queue.top();Queue.pop();long long b=Queue.top();Queue.pop();Queue.push(a+b);mincost+=a+b;}printf("%ld\n",mincost);while(!Queue.empty())Queue.pop();}return 0;}
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
- HDU 4247 A Famous ICPC Team
- 最小(大)生成树_裸题(HDU-1863,POJ-2377)
- cocos2dx-3.0(30) 动作进度 ProgressTimer
- ASP:Panel控件(容器控件)
- hdoj1115 Lifting the Stone
- poj 3253 fence repair
- 架构资料
- gets(s)、getchar()和scanf("%s",s)
- 在ubuntu 12.04 上安装openCV 2.4.9 (wandboard-quad iMX6 ARM9 quadcore)
- 876754653454
- ASP:FileUpload控件(文件上传控件)
- Container With Most Water
- jQuery 数据操作函数
- Java程序员应具备的技能