Links: http://acm.hust.edu.cn/vjudge/problem/19200
Analysis: What does the XI have to do with this question? Binary tree just corresponds to binary, the root node is expressed as 0, the left subtree is i*2+0, the right subtree is i*2+1, all leaf nodes can be used 0~ (1<<n)-1 (n is the number of layers, the root node is the No. 0 layer) of the number.
1#include <cstdio>2 3 intMain () {4 intN, Kase =0;5 while(SCANF ("%d", &n) = =1&&N) {6 intx[Ten];Charbuf[ $];7 for(inti =0; I < n; i++) scanf ("%s", buf);8 intm =1<< N;intleaf[ $];9scanf"%s", buf);Ten for(inti =0; I < m; i++) OneLeaf[i] = buf[i]-'0'; Aprintf"S-tree #%d:\n", ++Kase); - intQ scanf"%d", &q); - intdir[Ten]; the for(inti =0; i < Q; i++) { -scanf"%s", buf); - intv =0; - for(intj =0; J < N; J + +) +v = v *2+ Buf[j]-'0'; -printf"%d", Leaf[v]); + } Aprintf"\ n"); at } - return 0; -}
UVa712 s-trees (binary tree)