Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 6973 | Accepted: 3341 |
Description
Input
Output
Sample Input
01 10 0010 0000 9 01 10 010 0000 9
Sample Output
Set 1 is immediately decodable Set 2 is not immediately decodable
Source
//HDU ,PKU都过了,JOJ的没过,我表示鸭梨很大 #include<iostream> #include<string> using namespace std; struct dictree { int child[2]; bool f;/*记录当前单词出现的次数*/ } tree[700010]; int root; int nownode=0; bool insert(string source) { int len,i,j; int current,newnode; len=source.size(); if(len==0) return 1; current=root;//从根节点开始寻找 for(i=0; i<len; i++)/*逐个插入字符*/ { if(tree[current].child[source[i]-'0']!=-1)/*存在*/ { current=tree[current].child[source[i]-'0']; } else { ++nownode;//看现在第几个node还未被使用 newnode=nownode; for(j=0; j<2; j++) tree[newnode].child[j]=-1;//初始化 tree[current].child[source[i]-'0']=newnode; current=newnode; tree[current].f=false; } if(tree[current].f) return 0; } tree[current].f=true; return 1; } int main() { char temp[11]; int i; root=0; nownode=0; for(i=0; i<2; i++) tree[root].child[i]=-1;//初始化 tree[root].f=false; string a; bool flag=1; int cas=1; while(cin>>a) { if(a[0]=='9') { if(flag) { printf("Set %d is immediately decodable/n",cas++); flag=1; } else { printf("Set %d is not immediately decodable/n",cas++); flag=1; } root=0; nownode=0; for(i=0; i<2; i++) tree[root].child[i]=-1;//初始化 tree[root].f=false; } if(!flag) continue; flag=insert(a); } return 0; }