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轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...
随机推荐
- bash脚本编程
一.bash中的变量 变量类型: 本地变量:只对当前shell进程有效,对其子shell以及其它shell都无效; 定义变量:[set]Var_name="value" 变量赋 ...
- spm_hrf
a=spm_hrf(0.72); n1=MOTOR_taskdesign(1,:);cn1=conv(n1,a);plot(cn1); block design hrf
- [经验] Java 使用 netty 框架, 向 Unity 客户端的 C# 实现通信 [1]
这是一个较为立体的思路吧 首先是技术选型: 前端 : HTML5 + jQuery ,简单暴力, 不解释 服务端 : Spring Boot + Netty + Redis/Cache 客户端 ...
- Vue源码(上篇)
某课网有个488人名币的源码解读视频看不起,只能搜很多得资料慢慢理解,看源码能知道大佬的功能模块是怎么分块写的,怎么复用的,已经vue是怎么实现的 资料来自 vue源码 喜欢唱歌的小狮子 web喵喵喵 ...
- Python 基础之循环结构 while
一.while循环介绍 while 循环 可以提高代码的效率,减少代码的冗余 while 条件表达式: code1 code2如果条件表达式成立,返回Ture,就执行其中的代码块 1.基本 ...
- 启动易EZB Systems EasyBoot V6.5.1.669 + 注册码
启动易EasyBoot可以简单的让您制作启动光盘,它可以制作光盘启动菜单.自动生成启动文件.并生成可启动ISO文件.只要通过CD-R/W刻录软件即可制作完全属于自己的启动光盘. EasyBoot 6. ...
- C语言结构体指针(指向结构体的指针)详解
C语言结构体指针详解 一.前言 一个指向结构体的变量的指针表示的是这个结构体变量占内存中的起始位置,同样它也可以指向结构体变量数组. *a).b 等价于 a->b. "."一 ...
- redis之List类型常用方法总结
redis之List类型常用方法总结 格式: 存---LPUSH key value [value ...] 取--LRANGE key start stop lpush key value [val ...
- 四、spring集成ibatis进行项目中dao层基类封装
Apache iBatis(现已迁至Google Code下发展,更名为MyBatis)是当前IT项目中使用很广泛的一个半自动ORM框架,区别于Hibernate之类的全自动框架,iBatis对数据库 ...
- vue实现登陆单页面
一 实现页面的布局 1. 首先在components里建一个login.vue <template> <div class=login_container> 登陆组件 < ...