UVA - 712 S-Trees(S树)
题意: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 ;
}
UVA - 712 S-Trees(S树)的更多相关文章
- UVa 839 -- Not so Mobile(树的递归输入)
UVa 839 Not so Mobile(树的递归输入) 判断一个树状天平是否平衡,每个测试样例每行4个数 wl,dl,wr,dr,当wl*dl=wr*dr时,视为这个天平平衡,当wl或wr等于0是 ...
- UVa 712 S树
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 112 - Tree Summing(树的各路径求和,递归)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVA 11402 - Ahoy, Pirates!(段树)
UVA 11402 - Ahoy, Pirates! 题目链接 题意:总的来说意思就是给一个01串,然后有3种操作 1.把一个区间变成1 2.把一个区间变成0 3.把一个区间翻转(0变1,1变0) 思 ...
- UVa 1471 Defense Lines - 线段树 - 离散化
题意是说给一个序列,删掉其中一段连续的子序列(貌似可以为空),使得新的序列中最长的连续递增子序列最长. 网上似乎最多的做法是二分查找优化,然而不会,只会值域线段树和离散化... 先预处理出所有的点所能 ...
- UVA 11235 Frequent values 线段树/RMQ
vjudge 上题目链接:UVA 11235 *******************************************************大白书上解释**************** ...
- hdu 3015 Disharmony Trees (离散化+树状数组)
Disharmony Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- uva 1519 - Dictionary Size(字典树)
题目链接:uva 1519 - Dictionary Size 题目大意:给出n个字符串组成的字典.如今要加入新的单词,从已有单词中选出非空前缀和非空后缀,组成新单词. 问说能组成多少个单词. 解题思 ...
- UVA 10869 - Brownie Points II(树阵)
UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...
随机推荐
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)D(树状数组)
//树状数组中数组的特性,有更巧妙的方法.//我们知道在树状数组中,对于数组tree[i],它所维护的区间为[i−lowbit(i)+1,i]//所以对于tree[2^i],它所维护的区间就为[1,2 ...
- 解题报告:luogu P5543 [USACO19FEB]The Great Revegetation S
题目链接:P5543 [USACO19FEB]The Great Revegetation S 好坑啊,都身败名裂了. 思路一: 考虑染色法,跑一遍搜所就好了,不给代码了. 思路二: 考虑并查集,我想 ...
- Ngnix简介
Nginx的产生 没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一资源描述符(Unifor ...
- C++中%d,%s,%x,%f,%.100f,%的意思
C++中%d,%s,%x,%f,%.100f,%的意思 标准格式化输出:格式字符有d,o,x,u,c,s,f,e,g等. 格式说明:由“%”和格式字符组成,如%d.%f等. %c用来输出一个字符; % ...
- [Database] MAC MySQL中文乱码问题
1 确保数据库编码设置, 可修改my.cnf mysql> show variables like '%character%'; +--------------------------+---- ...
- darknet简述
概述 darknet官网:https://pjreddie.com/darknet/ https://github.com/AlexeyAB/darknet Darknet是一个比较小众的深度学 ...
- mybatis注解中写SQL语句
参考: https://blog.csdn.net/gebitan505/article/details/54929287/https://blog.csdn.net/KingBoyWorld/art ...
- D - Beautiful Graph (深搜)
这个题深搜容易解决,结果用了广搜,动手之前还是要想清楚,然后自己的代码写错的情况下,没有重写,而是在原有的基础上,进行修改,结果有个判定的初始化条件放错位置,浪费了一个小时... 就是给一个无向图,任 ...
- python表白实现代码(可视化与动画版)
python表白实现代码(可视化与动画版)如何优雅而又高大上地对自己的心爱女神表白了? ? ? 试试python表白的实现方式吧,是动画版的哦,保证可以如你所愿 ! ! !最终的实现效果如下: 具体实 ...
- spring bean容器学习
bean是Spring种最核心的东西 ,如果说Spring是个水桶的话,bean就是桶里面的水,桶里面没有水也就没有意义了. public class MyTestBean { private Str ...