霍夫曼樹計算 WPL

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   for   sp   div   c   

 1 #include<stdio.h> 2 #include<iostream> 3 #include<string> 4 #include<string.h> 5 #include<algorithm> 6 #include<iomanip> 7 #include<vector> 8 #include<time.h> 9 #include<queue>10 #include<stack>11 #include<iterator>12 #include<math.h>13 #include<stdlib.h>14 #include<limits.h>15 //#define ONLINE_JUDGE16 #define ll long long17 18 using namespace std;19 priority_queue <ll, vector<ll>, greater<ll> > Q;20 #define N 50005021 22 int main()23 {24     int n;25     while(scanf("%d",&n)!=EOF){26         for(int i=0;i<n;i++){27             int t;28             scanf("%d",&t);29             Q.push(t);30         }31         if(Q.size() > 1){32             ll num = 0;33             while(Q.size()>1){34                 ll n = Q.top();Q.pop();35                 ll m = Q.top();Q.pop();36                 num += (n+m);37                 Q.push(n+m);38             }39             printf("%lld\n",num);40         }else{41             int t = Q.top();42             printf("%d\n",t);43         }44     }45     return 0;46 }

 

霍夫曼樹計算 WPL

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.