题意:0往左走,1往右走,已知所有叶子的值,每个查询都是根结点到叶子结点的路径,路径的每一个点分别对应着x1,x2,x3……但是实际上的S树的路径可能并非是x1,x2,x3……

分析:先存路径变量的顺序,来控制最后访问的顺序。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
char s[MAXN];
char t[MAXN];
vector<int> order;
vector<char> v[];
int POW[];
void init(){//2的i次方
int tmp = ;
for(int i = ; i <= ; ++i){
tmp *= ;
POW[i] = tmp;
}
}
int main(){
int n;
int kase = ;
init();
while(scanf("%d", &n) == ){
if(n == ) return ;
for(int i = ; i < ; ++i) v[i].clear();
order.clear();
for(int i = ; i < n; ++i){
char tmp[];
scanf("%s", tmp);
order.push_back(tmp[] - '');//S树的变量顺序
}
scanf("%s", s);
int m;
scanf("%d", &m);
for(int k = ; k < m; ++k){
scanf("%s", t);
for(int i = ; i < n; ++i){
v[i + ].push_back(t[i] - '');//存x[i+1]的m次查询的值
}
}
printf("S-Tree #%d:\n", ++kase);
for(int i = ; i < m; ++i){
int cnt = ;//根结点标号为1
for(int j = ; j < n; ++j){
if(!v[order[j]][i]){//若为0,则2i;否则2i+1
cnt *= ;
}
else{
cnt = cnt * + ;
}
}
printf("%c", s[cnt - POW[n]]);
}
printf("\n\n");
}
return ;
}

最新文章

  1. 【转】安全传输协议SSL和TLS及WTLS的原理
  2. Linux服务器宕机案例一则
  3. mongodb(mongoose-redis-cache)
  4. JSON后端页面解析
  5. sharepoint2013小技巧
  6. lamda 表达式
  7. JavaScript截取字符串的Slice、Substring、Substr函数简单比较还有indexof函数应用
  8. 自定义MapReduce中数据类型
  9. Python学习第四篇——列表访问与判定
  10. php安装扩展
  11. m3u8文件下载合并的一种方法
  12. powerdesidgner1
  13. Mysql分页之limit用法与limit优化
  14. [Linux] 修改用户名密码
  15. LeetCode--168--Excel表列名称
  16. 验证手机号码的JS方法
  17. nodejs使用multiparty模块实现文件上传(另附express.bodyParser()的说明)
  18. 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
  19. 创建Podfile,添加类库,中途添加库指令
  20. yii2自定义500错误

热门文章

  1. 123、Java面向对象之引用传递实例一
  2. Spring Cloud入门-Nacos实现注册和配置中心(Hoxton版本)
  3. HTML&lt;video&gt;&lt;/video&gt;视频无法自动播放
  4. linux 查看Apache Tomcat日志访问IP前10
  5. 重要参考SQL
  6. 用 lastIndexOf()、substr()、split()方法截取一段字符串
  7. SystemVerilog Assertion 设计、调试、测试总结(1)
  8. bzoj 2111: [ZJOI2010]Perm 排列计数
  9. 093、Java中String类之字符串是匿名对象
  10. NSArary自定义对象排序 NSComparator, compare