【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

dfs模拟一下就好。
先预处理一个dfs.
搞出来x叶子节点它的值是什么

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
*/
#include <bits/stdc++.h>
using namespace std; const int N = 10; int n,Q;//depth
int de[N];
int val[N],key[1024],now;
string KEY; void dfs1(int x,int dep){
if (dep>n){
key[x] = KEY[now++] - '0';
return;
}
dfs1(x*2,dep+1);
dfs1(x*2+1,dep+1);
} int dfs2(int x,int dep){
if (dep > n){
return key[x];
}
if (val[de[dep]]==0){
return dfs2(x*2,dep+1);
}else {
return dfs2(x*2+1,dep+1);
}
} int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int Kase = 0;
while (cin>> n && n){
cout << "S-Tree #" << ++Kase <<':'<<endl;
now = 0;
for (int i = 1;i <= n;i++){
string temp;
cin >> temp;
de[i] = temp[1]-'0';
}
cin >> KEY; dfs1(1,1); cin >> Q;
for (int i = 1;i <= Q;i++){
string temp;
cin >> temp;
for (int j = 0;j < n;j++)
val[j+1] = temp[j] - '0';
cout << char(dfs2(1,1) + '0');
}
cout << endl;
cout << endl;
} return 0;
}

【习题 6-2 UVA - 712】S-Trees的更多相关文章

  1. UVa 712 S树

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVA 712 S-Trees

    二叉树? 怒水~~ 注意一下查询与x值的对应关系就好~ #include <iostream> #include <cstring> #include <cstdio&g ...

  3. UVa 143 - Orchard Trees

    题目大意:果园里的树排列成矩阵,它们的x和y坐标均是1~99的整数.输入若干三角形,依次统计每一个三角形内部和边界上共有多少棵树. 三角形P0P1P2有向面积为A:2A = x0y1 + x2y0 + ...

  4. UVa 712

    这个题根本不用建树,因为是完全二叉树,可以把这个想成二进制.对于根是二进制数的首位,之后依次类推.到最后的叶子节点就是从0到pow(2,n)-1. 关键在于在第一次输入的不是按照x1,x2,x3,x4 ...

  5. UVa 712 S-Trees(二进制转换 二叉树叶子)

    题意: 给定一颗n层的二叉树的叶子, 然后给定每层走的方向, 0代表左边, 1代表右边, 求到达的是那一个叶子. 每层有一个编号, 然后n层的编号是打乱的, 但是给的顺序是从1到n. 分析: 先用一个 ...

  6. 【例题 6-7 UVA - 122 】Trees on the level

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二叉树的话,直接用数组存就好了. 写个bfs记录一下答案. [代码] #include <bits/stdc++.h> ...

  7. UVA - 143 Orchard Trees (点在三角形内)

    题意: 给出三角形的三个点的坐标(浮点数),     问落在三角形内及三角形边上的整点有多少? 思路:所有点暴力判断(点的范围1-99,三角形可能是0-100,因为这个WA了一下orz) AC代码: ...

  8. UVA - 712 S-Trees(S树)

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

  9. S-Trees UVA - 712

      A Strange Tree (S-tree) over the variable set Xn = {x1,x2,...,xn} is a binary tree representing a ...

随机推荐

  1. obdg反汇编破解crackme

    obdg是一个反汇编软件 直接将要反汇编的exe文件拖入或者file->open打开文件,等待一段时间就会显示出来 界面中分别为汇编代码(程序内存内容),寄存器内容,数据内存内容,栈内容 代码界 ...

  2. 【Linux端口大全】

    2端口:管理实用程序 3端口:压缩进程 5端口:远程作业登录 7端口:回显 9端口:丢弃 11端口:在线用户 13端口:时间 17端口:每日引用 18端口:消息发送协议 19端口:字符发生器 20端口 ...

  3. ios-字符串替换-正则表达式-例子

    需求:在html中查找并替换相应的html标签 代码实现 - (NSString *)replaceImageHtml:(NSString *)oldHtml { NSString *regex = ...

  4. js实现table排序(jQuery下的jquery.sortElements)

    项目中要实现table排序的功能. 网上有非常多解决方式,非常多都基于jQuery. jquery.tablesorter.大小17KB.只是他的首页在ie10下兼容性有点问题. DataTables ...

  5. hdu 5312 Sequence(数学推导——三角形数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others)  ...

  6. 数据库范式小结 1NF 2NF BCNF 3NF 4NF DB normal form

    1. 1NF指关系中的每个变量不可再分 2. 2NF指消除了非主属性对码(candidate key)的部分依赖的1NF 比如(S#,C#)-> SN ,(S#,C#)-> SD .S#- ...

  7. UVa 10101 - Bangla Numbers

    题目:将数字数转化成数字加单词的表示形式输出. 分析:数论.简单题.直接分成两部分除10000000的商和余数,分别输出就可以. 说明:注意输入为数字0的情况,还有long long类型防止溢出. # ...

  8. 72.调用req.flash('error', '用户已存在!'); 时候 报错 "req.flash is not a function"

    在app.js 中调用app.use 的顺序有关 app.use(session({ secret: settings.cookieSecret, key: settings.db,//cookie ...

  9. ZJU 2425 Inversion

    Inversion Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID:  ...

  10. 使用Spring实现MySQL读写分离(转)

    使用Spring实现MySQL读写分离 为什么要进行读写分离 大量的JavaWeb应用做的是IO密集型任务, 数据库的压力较大, 需要分流 大量的应用场景, 是读多写少, 数据库读取的压力更大 一个很 ...