BZOJ 1724: [Usaco2006 Nov]Fence Repair 切割木板 贪心_堆_反向思考

BZOJ 1724: [Usaco2006 Nov]Fence Repair 切割木板 贪心_堆_反向思考

Code:

#include
#define setIO(s) freopen(s".in","r",stdin)
#define ll long long  
using namespace std;
priority_queue, greater >Q; 
int main()
{
    //setIO("input"); 
    int n;
    ll u,cur,sum=0; 
    scanf("%d",&n); 
    for(int i=1;i<=n;++i) scanf("%lld",&u), Q.push(u);  
    while(!Q.empty())
    { 
        cur=Q.top(); Q.pop();     
        if(!Q.empty()) 
        {
            cur+=Q.top(); Q.pop(); 
            Q.push(cur); 
            sum+=cur; 
        }
    }
    printf("%lld\n",sum); 
    return 0; 
}

  

posted @ 2019-06-05 09:16 EM-LGH 阅读( ...) 评论( ...) 编辑 收藏

你可能感兴趣的:(BZOJ 1724: [Usaco2006 Nov]Fence Repair 切割木板 贪心_堆_反向思考)