-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuffmanDecoding.html
More file actions
542 lines (437 loc) · 18.2 KB
/
HuffmanDecoding.html
File metadata and controls
542 lines (437 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>TopCoder SRM 308 - 450: HuffmanDecoding</title>
<link type="image/x-icon" rel="shortcut icon" href="http://www.topcoder.com/i/favicon.ico"/>
<style type="text/css">
/* font */
body {
font-family: Helvetica, Arial, Verdana, sans-serif;
font-size: 16px;
line-height: 1.2em;
}
ul.constraints > li:before, ul.notes > li:before {
font-family: monospace;
font-weight: normal;
}
.heading {
font-weight: bold;
font-size: 175%;
line-height: 1.2em;
}
.section .section-title {
font-weight: bold;
font-size: 125%;
}
ol.testcases > li:before {
font-family: monospace;
}
type {
font-weight: bold;
font-family: monospace;
}
li.testcase .data {
font-family: monospace;
line-height: 1.5em;
}
/* layout */
.heading {
margin-top: 0.1em;
margin-bottom:0.1em;
text-align: center;
}
.section .section-title {
margin-top : 1em;
margin-bottom: 1em;
}
.problem-intro, note, user-constraint {
padding-left: 1.25em;
}
/* Lists */
ul.constraints, ul.notes, ul.variables, ul.problem-definition-lines {
list-style-type: none;
padding: 0px;
}
ul.constraints > li:before {
content: "-";
position:relative;
margin-left: 0px; /* optional, for multiline li element */
left: 0.625em;
}
ul.notes > li:before {
content: "-";
position:relative;
margin-left: 0px; /* optional, for multiline li element */
left: 0.625em;
}
/* Testcases */
li.testcase {
line-height: 1.1em;
padding-top: 0.625em;
padding-bottom: 0.625em;
overflow: auto;
}
li.testcase > .testcase-content > div { padding-bottom: 0.5em; padding-left: 1em; }
li.testcase .testcase-comment {
margin: 0;
padding-left: 1em;
}
.testcase-comment p:first-child { margin-top: 0; }
.testcase-comment p:last-child { margin-bottom: 0; }
li.testcase .testcase-content {
margin: 0.31em;
}
/* Data and variables */
.testcase-output {
padding: 0.2em 1em 0.2em 0em;
}
.variables, .testcase-output {
margin-left: 0.5em;
display: table;
margin-bottom: 0px;
margin-top: 0px;
}
.variable {
display: table-row;
}
.variable .name {
padding: 0.2em 0em 0.2em 1em;
font-weight: bold;
display: table-cell;
text-align: right;
}
.testcase-output .prefix {
padding: 0.2em 0em 0.2em 1em;
display: table-cell;
}
.testcase-output .prefix:after {
content : ":";
padding-right: 0.5em;
}
.variable .name:after {
font-weight: bold;
content : ":";
padding-right: 0.5em;
}
.variable .value, .testcase-output .value {
padding: 0.2em 1em 0.2em 0em;
display: table-cell;
}
ol.testcases {
padding: 0px;
counter-reset: test_number -1;
}
ol.testcases > li {
list-style:none;
}
ol.testcases > li:before {
counter-increment:test_number;
display: block;
clear: both;
content:counter(test_number) ")";
color: inherit;
background: inherit;
}
/* Problem Definition */
.problem-definition, .problem-limits {
padding-left: 1.25em;
}
.problem-definition-lines, .limit-lines {
display: table;
margin-top: 0px;
margin-bottom: 0px;
padding-left: 0px;
}
.definition-line, .limit-line {
display: table-row;
height: 1.5em;
overflow: auto;
}
.limit-name:after {
content: ":";
margin-right: 1em;
}
.definition-name, .definition-value, .limit-name, .limit-value {
display: table-cell;
}
.definition-value {
padding-left: 0.5em;
}
.definition-name:after {
content: ":";
}
#contest-division:before {
content: "Div ";
}
#problem-score:before {
content: "- Problem ";
}
#problem-name {
display: block;
}
/* Tags, hidden default */
.tag {
visibility: hidden;
position: absolute;
}
body {
/* font color */
color: #333333;
/* background color */
background-color: white;
}
.section .section-title {
/* title color */
color: black;
}
li.testcase .data {
/* highlight color */
background: #eee;
}
</style>
</head>
<body>
<h1 class="heading">
<span id='contest-name'>SRM 308</span>
<span id='contest-division'>2</span>
<span id='problem-score'>450</span>
<span id='problem-name'>HuffmanDecoding</span>
</h1>
<hr />
<!-- Problem Statement -->
<div class="section">
<h2 class="section-title">Problem Statement</h2>
<div class="problem-intro">
<intro><p>When text is encoded using Huffman codes, each symbol is replaced by a string of 0s and 1s called a bit string representation. The replacement is done in such a way that the bit string representation of a symbol is never the prefix of the bit string representation of any other symbol. This property allows us to unambiguously decode the encoded text.</p>
<p>You will be given a <type>String</type> <b>archive</b> and a <type>String[]</type> <b>dictionary</b>. The i-th element of <b>dictionary</b> will be the bit string representation of the i-th uppercase letter. Decode <b>archive</b> using <b>dictionary</b> and return the result as a single <type>String</type>.</p></intro>
</div>
</div>
<!-- Problem definition -->
<div class="section" id="definition">
<h2 class="section-title">Definition</h2>
<div class="problem-definition">
<ul class="problem-definition-lines">
<li class="definition-line" id='class-line'>
<span class='definition-name'>Class</span>
<span class='definition-value'>HuffmanDecoding</span>
</li>
<li class="definition-line" id='method-line'>
<span class='definition-name'>Method</span>
<span class='definition-value'>decode</span>
</li>
<li class="definition-line" id='parameters-line'>
<span class='definition-name'>Parameters</span>
<span class='definition-value'>
string
,
vector<string>
</span>
</li>
<li class="definition-line" id='returns-line'>
<span class='definition-name'>Returns</span>
<span class='definition-value'>
string
</span>
</li>
<li class="definition-line" id='signature-line'>
<span class='definition-name'>Method signature</span>
<span class='definition-value'>
string decode(string archive, vector<string> dictionary)
</span>
</li>
</ul>
<div class="problem-definition-public-tip">(be sure your method is public)</div>
</div>
</div>
<!-- Limits -->
<div class="section">
<h2 class="section-title">Limits</h2>
<div class='problem-limits'>
<ul class="limit-lines">
<li class='limit-line'>
<span class='limit-name'>Time limit (s)</span>
<span class='limit-value'>2.000</span>
</li>
<li class='limit-line'>
<span class='limit-name'>Memory limit (MB)</span>
<span class='limit-value'>64</span>
</li>
</ul>
</div>
</div>
<!-- Constraints -->
<div class="section">
<h2 class="section-title">Constraints</h2>
<ul class="constraints">
<li><user-constraint><b>archive</b> will contain between 1 and 50 characters, inclusive. </user-constraint></li>
<li><user-constraint><b>archive</b> will contain only the characters '0' (zero) and '1' (one).</user-constraint></li>
<li><user-constraint><b>dictionary</b> will contain between 1 and 26 elements, inclusive. </user-constraint></li>
<li><user-constraint>Each element of <b>dictionary</b> will contain between 1 and 50 characters, inclusive. </user-constraint></li>
<li><user-constraint>Each element of <b>dictionary</b> will contain only the characters '0' (zero) and '1' (one).</user-constraint></li>
<li><user-constraint>No element of <b>dictionary</b> will be a prefix of any other element of <b>dictionary</b>.</user-constraint></li>
<li><user-constraint><b>archive</b> will be decodable using <b>dictionary</b></user-constraint></li>
</ul>
</div>
<!-- Test cases -->
<div class="section">
<h2 class="section-title">Test cases</h2>
<ol class="testcases" start='0'>
<li class="testcase">
<div class="testcase-content">
<div class="testcase-input">
<div class='tag'>input</div>
<ul class="variables">
<li class="variable data">
<span class="name data">archive</span>
<span class="value data">
"101101"
</span>
</li>
<li class="variable data">
<span class="name data">dictionary</span>
<span class="value data">
{"00",<br /> "10",<br /> "01",<br /> "11"}
</span>
</li>
</ul>
</div>
<div class="testcase-output">
<div class='tag'>output</div>
<span class="prefix data">Returns</span>
<span class="value data">
"BDC"
</span>
</div>
<div class="testcase-annotation">
<div class='tag'>note</div>
<div class="testcase-comment">Because there are no elements in dictionary that are prefixes of other elements, only one element of dictionary will be a prefix of <b>archive</b>. In this case, it is the second element ("10") which represents 'B'. The rest of the text can be decoded using the same logic.</div>
</div>
</div>
</li>
<li class="testcase">
<div class="testcase-content">
<div class="testcase-input">
<div class='tag'>input</div>
<ul class="variables">
<li class="variable data">
<span class="name data">archive</span>
<span class="value data">
"10111010"
</span>
</li>
<li class="variable data">
<span class="name data">dictionary</span>
<span class="value data">
{ "0", "111", "10" }
</span>
</li>
</ul>
</div>
<div class="testcase-output">
<div class='tag'>output</div>
<span class="prefix data">Returns</span>
<span class="value data">
"CBAC"
</span>
</div>
<div class="testcase-annotation">
<div class='tag'>note</div>
<div class="testcase-comment">Note that elements of <b>dictionary</b> can be of different lengths.</div>
</div>
</div>
</li>
<li class="testcase">
<div class="testcase-content">
<div class="testcase-input">
<div class='tag'>input</div>
<ul class="variables">
<li class="variable data">
<span class="name data">archive</span>
<span class="value data">
"0001001100100111001"
</span>
</li>
<li class="variable data">
<span class="name data">dictionary</span>
<span class="value data">
{"1",<br /> "0"}
</span>
</li>
</ul>
</div>
<div class="testcase-output">
<div class='tag'>output</div>
<span class="prefix data">Returns</span>
<span class="value data">
"BBBABBAABBABBAAABBA"
</span>
</div>
<div class="testcase-annotation">
<div class='tag'>note</div>
<div class="testcase-comment">'1' is replaced by 'A', '0' is replaced by 'B'.</div>
</div>
</div>
</li>
<li class="testcase">
<div class="testcase-content">
<div class="testcase-input">
<div class='tag'>input</div>
<ul class="variables">
<li class="variable data">
<span class="name data">archive</span>
<span class="value data">
"111011011000100110"
</span>
</li>
<li class="variable data">
<span class="name data">dictionary</span>
<span class="value data">
{ "010", "00", "0110", "0111", "11", "100", "101" }
</span>
</li>
</ul>
</div>
<div class="testcase-output">
<div class='tag'>output</div>
<span class="prefix data">Returns</span>
<span class="value data">
"EGGFAC"
</span>
</div>
</div>
</li>
<li class="testcase">
<div class="testcase-content">
<div class="testcase-input">
<div class='tag'>input</div>
<ul class="variables">
<li class="variable data">
<span class="name data">archive</span>
<span class="value data">
"001101100101100110111101011001011001010"
</span>
</li>
<li class="variable data">
<span class="name data">dictionary</span>
<span class="value data">
{ "110", "011", "10", "0011", "00011", "111", "00010", "0010", "010", "0000" }
</span>
</li>
</ul>
</div>
<div class="testcase-output">
<div class='tag'>output</div>
<span class="prefix data">Returns</span>
<span class="value data">
"DBHABBACAIAIC"
</span>
</div>
</div>
</li>
</ol>
</div>
<hr />
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
</body>
</html>