Test Instructions Translation
There are multiple sets of data in the subject. Each set of data gives a string containing only ' 0 ' and ' 1 ' at the end of "9", if there is another substring in it, output "set &case is not immediately decodable", otherwise output "set & Case is immediately decodable ". NewLine. The case is counted starting from 1.
Thank @fuko_ibuki for the translation
Title Description
Pdf
Input/output format
Input Format:
output Format:
Input/Output sample
Input Sample # #:Copy
0110001000009011001000009
Sample # # of output:Copy
Set 1 is immediately decodableset 2 are not immediately decodable
Exercises
It's a relatively simple trie question.
First, because lazy special handling, first ordered by length, and then from small to large enumeration of each string, and at the end of marking.
If a marked point is passed, the previous string is the prefix.
1 /*2 Qwerta3 UVA644 Immediate decodability4 Accepted5 Code C++,0.99KB6 Submission Time 2018-10-19 15:04:587 time consuming/memory8 50ms, 0KB9 */Ten#include <algorithm> One#include <iostream> A#include <cstring> -#include <cstdio> - using namespacestd; the strings[ One]; - BOOLcmpstringQaq,stringqwq) { - returnQaq.length () <qwq.length (); - } + structemm{ - intnxt[2],tag; +}a[ the]; A intMain () at { - //freopen ("a.in", "R", stdin); - intt=0; - while(++t&&cin>>s[1]) - { - intn=1; in Do{if(s[n][0]=='9') Break; -} while(cin>>s[++n]); ton--; +Sort (s+1, s+n+1, CMP); - intCnt=0; theMemset (A,0,sizeof(a)); * intflag=0; $ for(intC=1; c<=n&&!flag;++c)Panax Notoginseng { - intk=0; the for(intI=0; I<s[c].length (); + +i) + { A if(!a[k].nxt[s[c][i]-'0']) thea[k].nxt[s[c][i]-'0']=++CNT; +k=a[k].nxt[s[c][i]-'0']; - if(A[k].tag) flag++; $ } $a[k].tag=1; - } - if(!flag) theprintf"Set%d is immediately decodable\n", T); - ElseWuyiprintf"Set%d is not immediately decodable\n", T); the } - return 0; Wu}
"uva644"immediate decodability (Trie