UVa 712
2024-08-24 22:12:37
这个题根本不用建树,因为是完全二叉树,可以把这个想成二进制。对于根是二进制数的首位,之后依次类推。到最后的叶子节点就是从0到pow(2,n)-1。
关键在于在第一次输入的不是按照x1,x2,x3,x4这样的顺序输入的,那么我们就默认他的输入时按从二进制高位到地位。对于查询是按x1,x2,x3,x4这样的顺序。所以不能直接对应,需要一些小的操作来让查询的输入和二进制对的上。
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
using namespace std;
const double Pi=3.14159265358979323846;
typedef long long ll;
const int MAXN=+;
const int dx[]={,,,,-};
const int dy[]={,-,,,};
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll mod=1e9+; int main()
{
int n;int cn=;
while(cin>>n&&n)
{
string str[];
for(int i=;i<=n;i++)
cin>>str[i];
string a; cin>>a;//从0开始的到pow(2,n)-1,
int m;cin>>m;
vector <char> V;
for(int i=;i<=m;i++)
{
string s;cin>>s;//输入每个序列
int cnt=; //在树中的位置
for(int i=;i<=n;i++)
{
cnt=cnt*+(s[str[i][]-''-]-'');
}
V.push_back(a[cnt]);
}
printf("S-Tree #%d:\n",cn++);
for(int i=;i<V.size();i++)
cout <<V[i];
cout <<endl<<endl;
}
return ;
}
最新文章
- json学习系列(8)JSON与JAVA数据的相互转换实例
- spring data mongodb中,如果对象中的属性不想加入到数据库字段中
- java float、double精度研究(转)
- TEXT文本编辑框4 点击按钮读取文本框内容到内表
- 管道实现进程间通讯 、WaitNamedPipe
- Chapter 5 Blood Type——12
- 将ipad作为电脑拓展屏或分屏的简单方法
- Pytorch自定义dataloader以及在迭代过程中返回image的name
- java黑魔法-反射机制-02-通过Java反射调用其他类方法
- python 回溯法 子集树模板 系列 —— 8、图的遍历
- angularjs也支持script形式的template
- 【转】float类型在内存中的表示
- HDU 6199 2017沈阳网络赛 DP
- GDAL读取影像并插值
- The Tao Of Programming翻译
- C#批量入库
- Luogu-3250 [HNOI2016]网络
- ABAP术语-Call Transaction
- Python \xd7\xaa\xd5\xbdOTT TV\xb1\xa6\xbd\xe0 编码
- SD卡给MCU升级