Title: give you a completely binary tree, and give you a xi1~xin-1 sequence, the first layer from the root to the leaves;
Each layer corresponds to an XI, the leaf is 0 or 1, now gives you some path, the output path corresponds to the value of the leaf;
The path is 01 strings, from the beginning to go down, 0 for the left subtree, 1 for the right subtree, corresponding to the order of x1~xn-1.
Analysis: Simulation. Direct Ann find the path to go over, because it is two fork tree, just corresponds to the binary number.
Note: The order of the paths is adjusted to the same as the tree in the calculation.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;int x[10],f[10];int leaf[200];int main () {int n,k,t = 1;char buf [200];while (~SCANF ("%d", &n) && N) {for (int i = 0; i < n; + + i) {scanf ("%s", buf); X[i] = Atoi (&buf[1] )-1;} scanf ("%s", buf); int m = 1<<n;for (int i = 0; i < m; + + i) leaf[i] = buf[i]-' 0 ';p rintf ("S-tree #%d:\n", T + +); scan F ("%d", &k), for (int i = 0; i < K; + + i) {scanf ("%s", buf), for (int j = 0; J < N; + + j) F[x[j]] = buf[j]-' 0 '; in T v = 0;for (int j = 0; J < N; + + j) v = 2*v+f[x[j]];p rintf ("%d", Leaf[v]);} printf ("\ n");} return 0;}
UVa 712-s-trees