S-Trees UVA712(二叉树)
来源:互联网 发布:ps cs3 mac版 编辑:程序博客网 时间:2024/06/10 06:15
题目读了半天,差点被吓住!题目本身很简单,就是一颗满二叉树,向左(2*temp),向右(2*temp+1),最后减去(1<<n)-1;(即非叶子结点的个数,因为储存叶子结点是从下表为1开始的)。
#include<cstdio>#include<cstring>using namespace std;const int maxn=1<<8;const int maxn2=10000;char X[8][2];char Term[maxn];char Common[maxn2];int main(){int n;int count=1;while(scanf("%d",&n)==1 && n){memset(Common,0,sizeof(Common)); //刚开始忘记清零,WA了一次for(int i=0;i<n;i++)scanf("%s",X[i]); //变量的输入本题中没有作用scanf("%s",Term+1);printf("S-Tree #%d:\n",count++);char s[8];int m;scanf("%d",&m);int k=0;for(int i=0;i<m;i++){scanf("%s",s);int temp=1;for(int j=0;j<strlen(s);j++){if(s[j]=='0')temp=2*temp;else temp=2*temp+1; }Common[k++]=Term[temp-(1<<n)+1];}printf("%s\n\n",Common);} return 0;}
0 0
- S-Trees UVA712(二叉树)
- UVa712 习题6-2 S树(S-Trees)
- UVA712 S-Trees
- UVA712-S-Trees
- S-Trees UVA712
- uva712 - S-Trees
- UVa712 - S-Trees
- uva712 - S-Trees
- UVA712 - S-Trees
- uva712- S-Trees
- uva712 -- S-Trees
- uva712 S-Tree (假二叉树重建)
- Uva712——S-Trees
- S-Trees(二叉树)
- 算法竞赛入门经典 第二版 习题6-2 S树 S-Trees uva712
- 算法入门经典习题6-2,uva712,S-Trees
- Uva712 S-Trees 【二分思想】【习题6-2】
- uva 712 S-Trees(利用二叉树的特点)
- 面试算法①——转圈打印矩阵
- Skin++程序发布问题
- 设计模式->创建型模式->抽象工厂模式
- 面试编程题笔记
- 电工学(上)-电工技术 秦曾煌(7版)
- S-Trees UVA712(二叉树)
- 2017年新开博客
- img vs background-img
- cf566f
- 算法中效率问题
- 1053 正弦函数
- Mybatis执行过程
- 兰州烧饼
- 算法提高 多项式输出