回分類題庫
d220: CP2 Lab Exercise: Huffman Encoding
出處:

Difficulity : N/A
Accepted : 8 Times | Submit :28 Times | Clicks : 1476
Accepted : 5 Users | Submit : 7 Users | Accepted rate : 71%
Time Limit :10000 ms | Memory Limit : 64000 KBytes
題目加入時間 : 2011-06-08 20:08

Content :

Write a Huffman encoding program.

You can suppose there is no same frequency when building the tree.
And when combining two nodes, the less frequency one shall be appended to left tree while most frequency on the right.

Define: Left: 0, right: 1

Input :

The first line is an integer n indicates there are n test case.
The first line of each test case is an integer k indicates how many characters to encode.
The following k line is a char c and an integer p indicates char c's frequency is p.

Output :

For each test case, output the encode result, the result is output from the leftmost leaf node to rightmost one.

Sample Input :

1
6
A 10
I 9
R 8
O 7
L 6
G 5

Sample Output :

I 00
A 01
G 100
L 101
O 110
R 111

Hint :


  

Author :


  Solve it!   Status Forum (0)

C++
C
JAVA
沒有解題記錄 32130. nothinglo (4 ms , 286KB)
32193. cp99703028 (8 ms , 286KB)
32139. cp96703035 (8 ms , 272KB)
32137. cp99703008 (8 ms , 274KB)
32129. cp99703036 (8 ms , 282KB)
沒有解題記錄

執行時間會受很多因素影響因此僅供參考,主機等級請看這裡