POJ3264 Balanced Lineup

Source: Internet
Author: User

    • Framer John had a piece of wood that he wanted to use to build a fence, and he had to ask Framer Don for help without a saw. FD request, FJ each cut open a piece of wood, will give the length of the plank of money. FJ want to spend the least, ask you for help.

    • Idea: Definitely a replica of the merged fruit! It's OK to take the plank as a merged plank. Be careful of the range of L, N, the final ans with int is not fit, to use a long long.

    • The code is as follows:

#include <iostream>#include <cstdio>#include <queue>using namespace STD;intn;priority_queue<Long Long> q;voidInit () {scanf("%d", &n);inttmp for(intI=1; i<=n;++i) {scanf("%d", &tmp);    Q.push (-TMP); }}voidWork () {intans=0; while(!q.empty ()) {intA=q.top (); Q.pop ();if(Q.empty ()) {printf("%lld",-ans);return; }intB=q.top ();        Q.pop ();        ans+= (A+B);    Q.push (A+B); }}intMain () {init (); Work ();return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ3264 Balanced Lineup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.