mm洗衣服,k818次列车,月魔官网
题目描述:
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
output
3 8 5 8sample output
34hint
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
using namespace std;
#define inf 0x3f3f3f3f
#define eps 1e-10
typedef long long int ll;
const int maxn=2e4+5;
const int mod=1e9+7;
int main()
{
priority_queue<int,vector<int>,greater<int> >que;
int n,a[maxn];
ll ans=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
que.push(a[i]);
}
while(que.size()>1)
{
int l1,l2;
l1=que.top();
que.pop();
l2=que.top();
que.pop();
ans=ans+l1+l2;
que.push(l1+l2);
}
cout<<ans<<endl;
}
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论