bzoj1724: [Usaco2006 nov]fence Repair Cutting Board

Source: Internet
Author: User

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <queue>6 using namespacestd;7 intN,a;8typedefLong Longll;9 ll ans;Ten voidReadint&x) { Onex=0;intf=1;Charch; A      for(Ch=getchar ();! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1; -      for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0'; x*=F; - } thepriority_queue<int,vector<int>,greater<int> >Heap; - intMain () { -Read (n), ans=0; -      for(intI=1; i<=n;i++) Read (a), Heap.push (a); +      for(intX,y,i=1; i<n;i++){ -x=heap.top (), Heap.pop (); +y=heap.top (), Heap.pop (); AAns+=x+y; Heap.push (x+y); at     } -printf"%lld\n", ans); -     return 0; -}
View Code

Practice: Heap Entry Questions, learn the usage of the system heap and fog (:

Dagen:priority_queue<int>heap;

Little Gan:priority_queue< int,vector<int>,greater<int> >heap;

Heap.top () function: The value of the element at the top of the heap;

Heap.pop () Process: Popup heap top element;

Heap.empty () function: heap empty or not, heap empty return 1, otherwise return 0;

Heap.push () Process: Adds an element to the heap and maintains the nature of the heap.

bzoj1724: [Usaco2006 nov]fence Repair Cutting Board

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.