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

【题意】

在这里输入题意

【题解】

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. ajax跨域过程

  2. 比JLRoutes更强大更好用的iOS开源路由框架—FFRouter

    目前iOS常用路由框架是JLRouter.HHRouter.MGJRouter. 但是这些路由库都各有不足,首先是JLRouter,用不到的功能繁多,而且基于遍历查找URL,效率低下.HHRouter ...

  3. [Python] Reuse Code in Multiple Projects with Python Modules

    A module is a function extracted to a file. This allows you to import the function and use it in any ...

  4. 安卓MP3播放器开发实例(3)之进度条和歌词更新的实现

    上一次谈了音乐播放的实现,这次说下最复杂的进度条和歌词更新.因为须要在播放的Activity和播放的Service间进行交互,所以就涉及了Activity对Service的绑定以及绑定后数据的传输,这 ...

  5. Codeforces 474D Flowers (线性dp 找规律)

    D. Flowers time limit per test:1.5 seconds memory limit per test:256 megabytes We saw the little gam ...

  6. Python Web框架Tornado的异步处理代码演示样例

    1. What is Tornado Tornado是一个轻量级但高性能的Python web框架,与还有一个流行的Python web框架Django相比.tornado不提供操作数据库的ORM接口 ...

  7. POJ 2104 K-th Number 静态主席树(裸

    题目链接:点击打开链接 题意: 给定n长的序列.q个询问 以下n个数字给出序列 每一个询问[l, r] k ,输出该区间中第k大的数 先建一个n个节点的空树.然后每次从后往前新建一棵树,依附原来的空树 ...

  8. 一次失败的PHP扩展开发之旅

    一次失败的PHP扩展开发之旅 By warezhou 2014.11.19 缘起 经过不断的持续迭代.我们部门的协程版网络框架(CoSvrFrame)最终出炉了!这本来是件喜大普奔的事情.可是随着新业 ...

  9. region实现大纲效果

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. mac: brew的删除

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" ...