Title: Https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=839&page=show_ problem&problem=653
Idea: The current node is K, left is 2k, right walk 2k + 1, get the last point, minus all the nodes in the front n layer, the corresponding 0 or 1 of the subscript is the answer.
/*S-tree (UVa 712)*/#include<iostream>#include<cstring>#include<vector>using namespacestd;Const intMAXN =Ten;intN;Chars[1<<MAXN], INPUT[MAXN];//Input and QueryintIDX[MAXN];//each layer corresponds to the variable XIvector<Char> output;//Output Query Resultsintsolve ();intMain () {//freopen ("Input.txt", "R", stdin); intCNT =0; while(CIN >> n && N! =0) {memset (s+1,0,sizeof(s+1)); memset (IDX,0,sizeof(IDX)); Output.clear (); for(intI=1; i<=n; i++){ Charstr[3]; CIN>>str; Idx[i]= str[1] -'0'; } intm; CIN>> s+1>>m; for(intI=1; i<=m; i++) {cin>> input+1; Output.push_back (S[solve ()); } cout<<"S-tree #"<< ++cnt <<":"<<Endl; for(intI=0; i<m; i++) cout<<Output[i]; cout<< Endl <<Endl; }}intsolve () {intK =1; for(intI=1; I<=strlen (input+1); i++){ intt = Input[idx[i]]-'0'; if(T = =0) K=2*K; Elsek=2*k +1; } //cout << K-(1<<n) + 1 << endl; return(K-(1<<n) +1); }
S-tree (UVa 712) Two-pronged tree