简单题, 就是用一棵树来表示一个布尔函数然后对一些输入的变量求函数值
题目已经把意思和解题思路都描述清楚了, 直接模拟即可
最后又被空行坑了一次 - -||
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <cassert>
#include <iomanip>
#pragma warning(disable:4996) //关掉4996警告
/*
Uva 712
关键 : 树的顺序存储 + 模拟
*/
using namespace std;
int main( ) {
//freopen("input.txt", "r", stdin);
vector<int> order;
bool leaves[1 << 8];
int N, M, Case = 0;
while ( cin >> N && N > 0 ) {
string tmp, result;
memset(leaves, 0, sizeof(leaves));
order.clear( );
for ( int i = 0; i < N; i++ ) {
cin >> tmp;
order.push_back(tmp.at(1) - '0');
}
cin >> tmp;
for ( int i = 0; i < tmp.length( ); i++ ) {
leaves[i] = tmp.at(i) - '0';
}
cin >> M;
while ( M-- ) {
cin >> tmp;
int Node = 1;
for ( int i = 0; i < order.size(); i++ ) { // tmp.length() 和 order.size()必须是 N (否则出错)
if ( tmp.at(order[i]-1) == '0' ) Node *= 2;
else Node = Node * 2 + 1;
}
result.push_back(leaves[Node - (1 << N)]+'0');
}
cout << "S-Tree #" << ++Case << ":" << endl;
cout << result << endl << endl;
}
system("pause");
return 0;
}