【习题 6-2 UVA - 712】S-Trees
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
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的更多相关文章
- UVa 712 S树
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 712 S-Trees
二叉树? 怒水~~ 注意一下查询与x值的对应关系就好~ #include <iostream> #include <cstring> #include <cstdio&g ...
- UVa 143 - Orchard Trees
题目大意:果园里的树排列成矩阵,它们的x和y坐标均是1~99的整数.输入若干三角形,依次统计每一个三角形内部和边界上共有多少棵树. 三角形P0P1P2有向面积为A:2A = x0y1 + x2y0 + ...
- UVa 712
这个题根本不用建树,因为是完全二叉树,可以把这个想成二进制.对于根是二进制数的首位,之后依次类推.到最后的叶子节点就是从0到pow(2,n)-1. 关键在于在第一次输入的不是按照x1,x2,x3,x4 ...
- UVa 712 S-Trees(二进制转换 二叉树叶子)
题意: 给定一颗n层的二叉树的叶子, 然后给定每层走的方向, 0代表左边, 1代表右边, 求到达的是那一个叶子. 每层有一个编号, 然后n层的编号是打乱的, 但是给的顺序是从1到n. 分析: 先用一个 ...
- 【例题 6-7 UVA - 122 】Trees on the level
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二叉树的话,直接用数组存就好了. 写个bfs记录一下答案. [代码] #include <bits/stdc++.h> ...
- UVA - 143 Orchard Trees (点在三角形内)
题意: 给出三角形的三个点的坐标(浮点数), 问落在三角形内及三角形边上的整点有多少? 思路:所有点暴力判断(点的范围1-99,三角形可能是0-100,因为这个WA了一下orz) AC代码: ...
- UVA - 712 S-Trees(S树)
题意:0往左走,1往右走,已知所有叶子的值,每个查询都是根结点到叶子结点的路径,路径的每一个点分别对应着x1,x2,x3……但是实际上的S树的路径可能并非是x1,x2,x3…… 分析:先存路径变量的顺 ...
- S-Trees UVA - 712
A Strange Tree (S-tree) over the variable set Xn = {x1,x2,...,xn} is a binary tree representing a ...
随机推荐
- CodeChef November Challenge 2013 部分题解
http://www.codechef.com/NOV13 还在比...我先放一部分题解吧... Uncle Johny 排序一遍 struct node{ int val; int pos; }a[ ...
- appid、appkey、appsecret、accesstoken,消息模板
app_id, app_key, app_secret , 对于平台来说, 需要给你的 你的开发者账号分配对应的权限:1. app_id 是用来标记你的开发者账号的, 是你的用户id, 这个id 在数 ...
- 如何修改Web.Config里面的值
0.先添加 <add key="MAXNUM" value="6" /> 1.读取值 string maxNum = ConfigurationMa ...
- Python协程一点理解
协程,又称微线程,纤程.英文名Coroutine. 线程是系统级别的它们由操作系统调度,而协程则是程序级别的由程序根据需要自己调度.在一个线程中会有很多函数,我们把这些函数称为子程序,在子程序执行过程 ...
- Swift学习笔记(14)--方法
1.分类 方法分为实例方法和类型方法 实例方法(Instance Methods):与java中的类似,略 类型方法(Type Methods):与java.oc中的类方法类似.声明类的类型方法,在方 ...
- Swift学习笔记(7)--控制流
1.For循环 //1.条件递增 for var index = 0; index < 3; ++index { println("index is \(index)") } ...
- 03015_DBUtils
1.概述 (1)如果只使用JDBC进行开发,我们会发现冗余代码过多,为了简化JDBC开发,本案例我们讲采用apache commons组件一个成员:DBUtils : (2)DBUtils就是JDBC ...
- 【Uva 1629】 Cake slicing
[Link]: [Description] 给你一个n*m的格子; 然后里面零零散散地放着葡萄 让你把它切成若干个小矩形方格 使得每个小矩形方格都恰好包含有一个葡萄. 要求切的长度最短; 问最短的切割 ...
- COGS——T 7. 通信线路
http://www.cogs.pro/cogs/problem/problem.php?pid=7 ★★ 输入文件:mcst.in 输出文件:mcst.out 简单对比时间限制:1.5 ...
- POJ——T3160 Father Christmas flymouse
Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 3496 Accepted: 1191 缩点,然后每个新点跑一边SPFA ...