Cod sursa(job #1549947)
| Utilizator | Data | 12 decembrie 2015 22:49:58 | |
|---|---|---|---|
| Problema | Coduri Huffman | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.7 kb |
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
ifstream in("huffman.in");
ofstream out("huffman.out");
int n, v[1000000];
long long lg,s;
priority_queue <long long, std::vector<int>, std::greater<int> > H;
int main()
{
int i, min1,min2,x,l;
in>>n;
for(i=1; i<=n; i++)
{
in>>x;
H.push(x);
}
i=1;
l=n;
while(H.size()>0)
{
min1=H.top();
H.pop();
if(H.size()>0)
{
min2=H.top();
H.pop();
s=min1+min2;
lg+=s;
H.push(s);
}
}
return 0;
}
